I'm getting this build error with Nuxt3.0 stable.
nuxi dev
works fine.
I get the following error when I run nuxi build
.
ERROR 'fileURLToPath' is not exported by __vite-browser-external, imported by node_modules/local-pkg/dist/shared.mjs 13:57:26
file: /node_modules/local-pkg/dist/shared.mjs:41:9
39: import path from "path";
40: import fs, { promises as fsPromises } from "fs";
41: import { fileURLToPath } from "url";
^
42:
43: // node_modules/.pnpm/yocto-queue@1.0.0/node_modules/yocto-queue/index.js
ERROR 'fileURLToPath' is not exported by __vite-browser-external, imported by node_modules/local-pkg/dist/shared.mjs 13:57:26
at error (node_modules/rollup/dist/es/shared/rollup.js:1858:30)
at Module.error (node_modules/rollup/dist/es/shared/rollup.js:12429:16)
at Module.traceVariable (node_modules/rollup/dist/es/shared/rollup.js:12788:29)
at ModuleScope.findVariable (node_modules/rollup/dist/es/shared/rollup.js:11440:39)
This is my nuxt.config.ts
export default defineNuxtConfig({
modules: ['@pinia/nuxt'],
runtimeConfig: {
},
hooks: {
'components:dirs'(dirs: any) {
dirs.push({
path: '~/components',
})
},
},
components: {
global: true,
},
nitro: {
preset: 'aws-lambda',
serveStatic: true,
},
app: {
baseURL: '/',
},
build: {
transpile: ['chart.js'],
},
typescript: {
shim: false,
strict: true,
},
vite: {
resolve: {
alias: {
'./runtimeConfig': './runtimeConfig.browser',
},
},
},
})
I tried these but build still doesn't work.
Polyfill node os module with vite/rollup.js
https://github.com/aws-amplify/amplify-js/issues/9639#issuecomment-1315152038
I didn't get to the root cause per se, but in my case something about my test was causing that issue to happen. Because of that I realized that my tests were being included in the build and I created a .nuxtignore
file with contents
**/*.test.*
to make sure tests are not compiled in and that solved the issue for me https://nuxtjs.org/docs/configuration-glossary/configuration-ignore/
(there are some other answers that talk about using a pollyfil - https://stackoverflow.com/a/70666018/35505)