vite-ssg
vite-ssg copied to clipboard
Workbox import error on build
Hey, I'm trying to build my app with vite ssg (created with the vitesse template).
Here is the output of pnpm build
[vite-ssg] Build for server...
vite v2.8.3 building SSR bundle for production...
✓ 54 modules transformed.
.vite-ssg-temp/manifest.webmanifest 0.38 KiB
.vite-ssg-temp/main.mjs 65.00 KiB
.vite-ssg-temp/assets/style.d6544e5f.css 13.68 KiB
[vite-ssg] An internal error occurred.
[vite-ssg] Please report an issue, if none already exists: https://github.com/antfu/vite-ssg/issues
file:///Users/nohehf/Documents/github/site_liste_serveur/frontVitesse/.vite-ssg-temp/main.mjs:28
import { Workbox } from "workbox-window";
^^^^^^^
SyntaxError: Named export 'Workbox' not found. The requested module 'workbox-window' is a CommonJS module, which may not support all module.exports as named exports.
CommonJS modules can always be imported via the default export, for example using:
import pkg from 'workbox-window';
const { Workbox } = pkg;
at ModuleJob._instantiate (node:internal/modules/esm/module_job:124:21)
at async ModuleJob.run (node:internal/modules/esm/module_job:181:5)
at async Promise.all (index 0)
at async ESMLoader.import (node:internal/modules/esm/loader:281:24)
at async importModuleDynamicallyWrapper (node:internal/vm/module:437:15)
at async build (/Users/nohehf/Documents/github/site_liste_serveur/frontVitesse/node_modules/.pnpm/[email protected]_1d9d03efcb68c10fe000b6b7ca1deeb9/node_modules/vite-ssg/dist/node/cli.cjs:180:87)
at async Object.handler (/Users/nohehf/Documents/github/site_liste_serveur/frontVitesse/node_modules/.pnpm/[email protected]_1d9d03efcb68c10fe000b6b7ca1deeb9/node_modules/vite-ssg/dist/node/cli.cjs:314:3)
ELIFECYCLE Command failed with exit code 1.
I have vite-ssg version 0.17.11
I've been running in to this same error but for other packages. I have not found a good solution yet, however have found a few temporary workarounds. You can change the format of the ssgOptions to format: 'cjs'
in the vite.config.ts file. Or you can modify the package.json of the workbox-window package to change either the "main" setting or add an exports conditional for import and require.
I ran into this as well. Would love a better solution than using cjs
in the config.
GoogleChrome/workbox#3066