vite-pwa / vite-plugin-pwa

Zero-config PWA for Vite
https://vite-pwa-org.netlify.app/
MIT License
3.05k stars 200 forks source link

Build Failed at yarn berry with pnp mode. #294

Open CXZ7720 opened 2 years ago

CXZ7720 commented 2 years ago

Hi. I have a problem with build in Yarn berry with pnp environment. Here's my Build Environment.

MacOS 12.4(M1 Max, also failed in Intel Mac) Yarn 3.2.1(berry, pnp mode enabled) NodeJS 16.13.2 Vite 2.9.9 vite-plugin-pwa 0.12.0 typescript 4.7.2

Here's my console error with pnp environment. image

By the way, I can successfully build at yarn classic(1.23.x) and yarn berry with node-modules linker.

userquin commented 2 years ago

@CXZ7720 try adding workbox-window as dev dependency

CXZ7720 commented 2 years ago

@userquin sorry for confusing, I updated attached image. image

userquin commented 2 years ago

@CXZ7720 can you disable the vite compress plugin to check if the problem is using also that plugin?

CXZ7720 commented 2 years ago

@userquin It fails same again.

image

userquin commented 2 years ago

@CXZ7720 can you provide the vite config file?

CXZ7720 commented 2 years ago

@userquin Here's my vite.config.ts

/* eslint-disable camelcase */
import react from '@vitejs/plugin-react'
import { defineConfig } from 'vite'
import { VitePWA } from 'vite-plugin-pwa'

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [
    react(),
    VitePWA(),
  ],
  publicDir: './public',
})
userquin commented 2 years ago

@CXZ7720 weird, try logging the error on write-sw-using-default-template.js, it seems to be shadowed by workbox-build (no stacktrace with the cause, maybe you need to add some extra dependency), add a console.error('weird', error) before line 68

throw new Error(`${errors_1.errors['sw-write-failure']} '${err.message}'`);
CXZ7720 commented 2 years ago

@userquin I'm affraid if it is stupid question, How can I edit the line of zipped file on ide?

userquin commented 2 years ago

upps, sorry, I don't check that module is inside a zip... (maybe it is just a name, it is a zip file on your file system?)

Maybe you can debug it, just add a breakpoint on line 68 and check the error

CXZ7720 commented 2 years ago

@userquin Yes It is zip file. I can't edit the file. image

danykina commented 2 years ago

Hi @CXZ7720 , I had the same problem and I just solved it by updating nodejs to the latest LTS available, 16.15.1. My current configuration is:

Yarn 3.2.1(berry, pnp mode enabled)
NodeJS 16.15.1
Vite 2.9.12
vite-plugin-pwa 0.12.0
typescript 4.7.4

Hope it can help you too!