Environment
- Operating System:
Darwin
- Node Version:
v18.16.1
- Nuxt Version:
3.6.2
- Nitro Version:
2.5.2
- Package Manager:
npm@9.5.1
- Builder:
vite
- User Config:
alias, app, css, plugins, components, modules, nitro
- Runtime Modules:
-
- Build Modules:
-
Reproduction
Stackblitz: https://stackblitz.com/edit/nuxt-starter-s9qxje?file=libs%2Fconfig%2Fload.ts
The project has next structure different from the standard:
/libs - folder contain "common code."
/libs/config/cli.js - an "internal" tool importing load-js.js
/libs/config/load-js.js - an es6 module contains code shared with an internal tool
/libs/config/load.ts - the TS wrapper that imports load-js.js
/server/api/hello.ts - the API endpoint that import /libs/config
The nuxt.config.ts:
// https://v3.nuxtjs.org/api/configuration/nuxt.config
export default defineNuxtConfig({
alias: {
'~/*': './*',
}
})
The package.json has the type "module":
{
"private": true,
"type": "module",
"scripts": {
"build": "nuxt build",
"dev": "HOST=0.0.0.0 nuxt dev",
"generate": "nuxt generate",
"preview": "nuxt preview",
"postinstall": "nuxt prepare"
},
"devDependencies": {
"@types/node": "^18",
"nuxt": "^3.6.2"
}
}
Describe the bug
When running npm run dev, I got the next error:
[1:52:21 PM] ERROR [worker reload] [worker init] Cannot find module '/home/projects/nuxt-starter-s9qxje/.nuxt/dev/load-js.js' imported from /home/projects/nuxt-starter-s9qxje/.nuxt/dev/index.mjs
The bundler does not include the ".js" file from the/libs directory even if it has an alias in nuxt.config.ts. It will have same issue if renamed to ".mjs".
The issue goes away if I remove "type": "module", from package.json - but it will break out internal tools due Node.js ESM loading error:
❯ node libs/config/cli.mjs
file:///home/projects/nuxt-starter-s9qxje/libs/config/cli.mjs:1
import {loadData} from './load-js.js'
^^^^^^^^
SyntaxError: Named export 'loadData' not found. The requested module './load-js.js' is a CommonJS module, which may not support all module.exports as named exports.
Additional context
No response
Logs
No response
Environment
Darwinv18.16.13.6.22.5.2npm@9.5.1vitealias,app,css,plugins,components,modules,nitro--Reproduction
Stackblitz: https://stackblitz.com/edit/nuxt-starter-s9qxje?file=libs%2Fconfig%2Fload.ts
The project has next structure different from the standard:
/libs- folder contain "common code."/libs/config/cli.js- an "internal" tool importingload-js.js/libs/config/load-js.js- an es6 module contains code shared with an internal tool/libs/config/load.ts- the TS wrapper that importsload-js.js/server/api/hello.ts- the API endpoint that import/libs/configThe
nuxt.config.ts:The
package.jsonhas the type "module":{ "private": true, "type": "module", "scripts": { "build": "nuxt build", "dev": "HOST=0.0.0.0 nuxt dev", "generate": "nuxt generate", "preview": "nuxt preview", "postinstall": "nuxt prepare" }, "devDependencies": { "@types/node": "^18", "nuxt": "^3.6.2" } }Describe the bug
When running
npm run dev, I got the next error:The bundler does not include the ".js" file from the
/libsdirectory even if it has an alias innuxt.config.ts. It will have same issue if renamed to ".mjs".The issue goes away if I remove
"type": "module",frompackage.json- but it will break out internal tools due Node.js ESM loading error:Additional context
No response
Logs
No response