vite-pwa / vite-plugin-pwa

Zero-config PWA for Vite

Home Page:https://vite-pwa-org.netlify.app/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

cant use registerSW when use pnpm install

shaddollxz opened this issue · comments

i can build vue code when i use npm install packages, but use pnpm there has error

// vite.config.ts
import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";
import { VitePWA } from "vite-plugin-pwa";

export default defineConfig({
    plugins: [vue(), VitePWA()],
});
// main.ts
import { createApp } from "vue";
import App from "./App.vue";
createApp(App).mount("#app");

import { registerSW } from "virtual:pwa-register"; // if not import , will no error
const updateSW = registerSW();
// packages.json
"dependencies": {
      "vue": "^3.2.25"
  },
  "devDependencies": {
      "@vitejs/plugin-vue": "^2.2.0",
      "typescript": "^4.5.4",
      "vite": "^2.8.0",
      "vite-plugin-pwa": "^0.11.13",
      "vue-tsc": "^0.29.8"
  }

node version: 16.13.1
npm version: 8.3.0
pnpm version: 6.24.2

the error is:

[vite-plugin-pwa] [vite]: Rollup failed to resolve import "workbox-window" from "..\..\..\@vite-plugin-pwa\virtual:pwa-register".   
This is most likely unintended because it can break your application at runtime.
If you do want to externalize this module explicitly add it to
`build.rollupOptions.external`
error during build:
Error: [vite]: Rollup failed to resolve import "workbox-window" from "..\..\..\@vite-plugin-pwa\virtual:pwa-register".
This is most likely unintended because it can break your application at runtime.
If you do want to externalize this module explicitly add it to
`build.rollupOptions.external`
    at onRollupWarning (D:\CodeTest\VITE\pwat\node_modules\.pnpm\vite@2.8.0\node_modules\vite\dist\node\chunks\dep-c9c9d3e5.js:39213:19)
    at onwarn (D:\CodeTest\VITE\pwat\node_modules\.pnpm\vite@2.8.0\node_modules\vite\dist\node\chunks\dep-c9c9d3e5.js:38991:13)     
    at Object.onwarn (D:\CodeTest\VITE\pwat\node_modules\.pnpm\rollup@2.67.1\node_modules\rollup\dist\shared\rollup.js:23119:13)    
    at ModuleLoader.handleResolveId (D:\CodeTest\VITE\pwat\node_modules\.pnpm\rollup@2.67.1\node_modules\rollup\dist\shared\rollup.js:22399:26)
    at D:\CodeTest\VITE\pwat\node_modules\.pnpm\rollup@2.67.1\node_modules\rollup\dist\shared\rollup.js:22360:26

@shaddollxz just add workbox-window as dev dependency:pnpm i -D workbox-window

commented

可以试一试:

pnpm i -D workbox-window