[Bug] Importing "virtual:pwa-register" could not be resolved
See original GitHub issueDescribe the bug
I’m building a PWA with Storybook and builder-vite. For convenience i wanted to add Vite-Plugin-PWA. To inform the user about an update a ReloadPrompt was added, which is also mentioned in the docs. The ReloadPrompt Component uses an import import { useRegisterSW } from "virtual:pwa-register/react"; but the builder does not seem to find the dependency.
Steps to reproduce the behavior
- Add Vite-Plugin-PWA to package.json
- Create the ReloadPrompt.tsx from here
yarn start-storybook
Expected behavior
Builder-vite should successfully import the virtual module
Screenshots and/or logs
The following dependencies are imported but could not be resolved:
virtual:pwa-register/react (imported by C:/Projekte/PWA/src/components/ReloadPrompt/ReloadPrompt.tsx)
Environment
- OS: [e.g. iOS] Windows
- Node.js version: [e.g. v12.17.0] v14.18.0
- Yarn version: [e.g. 6.14.4] 1.22.17
- Browser (if applicable): [e.g. chrome, safari] Brave
- Browser version (if applicable): [e.g. 22] 1.37.109
Additional context
When adding VitePluginPWA to the Vite config in Storybooks main.js the error is not shown, but Storybook wont build the iframe properly.
main.js:
const { VitePWA } = require("vite-plugin-pwa");
module.exports = {
core: {
builder: "@storybook/builder-vite",
},
stories: ["../src/**/**/*.stories.tsx"],
addons: ["@storybook/addon-essentials"],
// staticDirs: ['../public'],
framework: "@storybook/react",
async viteFinal(config, { configType }) {
config.optimizeDeps.include = [
"react-router-dom",
"http-proxy-middleware",
"vite",
"vite-plugin-pwa",
"fast-deep-equal",
...config.optimizeDeps.include,
];
config.plugins.push(VitePWA({}));
return config;
},
};
Issue Analytics
- State:
- Created a year ago
- Comments:7 (3 by maintainers)
Top Results From Across the Web
Parcel
$ parcel index.html Server running at http://localhost:1234 Build failed. @parcel/core: Cannot resolve 'ract' from './index.js' /dev/app/index.js: ...
Read more >Plugins - esbuild
If the plugin doesn't provide one, esbuild's default behavior won't resolve any imports in this module. This directory will be passed to any...
Read more >vite-plugin-pwa - npm
Start using vite-plugin-pwa in your project by running `npm i vite-plugin-pwa`. There are 26 other projects in the npm registry using ...
Read more >Progressive Web Application (PWA) - îles
clientsClaim and skipWaiting will be enabled; registerSW.js won't be generated unless explicitly enabled. Using a prompt for updates. When using ...
Read more >How do I implement a typescript service worker with vite ...
The first thing I did was to install the Vite plugin: npm i vite-plugin-pwa -D. then to the vite.config.ts I added the import...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Yes, here it is: https://github.com/Hydrair/MWE-import-virtual Using
yarnandyarn storybookit produces the same behavior like the original project. After optimizing dependencies.Alright fixed it with https://github.com/windicss/windicss/issues/267#issuecomment-947881136.
The
main.jsnow looks like this:Apparently by specifying the
rootVite knows how to look for the exports.Thanks for your help!