server imports lack the file extensions required by native esm
See original GitHub issueEnvironment
- Operating System:
Darwin
- Node Version:
v16.15.1
- Nuxt Version:
3.0.0-rc.8
- Package Manager:
yarn@1.22.19
- Builder:
vite
- User Config:
-
- Runtime Modules:
-
- Build Modules:
-
Reproduction
https://stackblitz.com/edit/nuxt-starter-a2yhjt?file=app.vue
Describe the bug
Importing anything from the node_modules without explicit extension will return an error that module is not found. Here is the example of importing a function from lodash. However if I import it with the explicit extension like ‘lodash/cloneDeep.js’ everything works well.
Additional context
No response
Logs
Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/home/projects/nuxt-starter-a2yhjt/node_modules/lodash/cloneDeep' imported from /home/projects/nuxt-starter-a2yhjt/.nuxt/dist/server/server.mjs
Did you mean to import lodash/cloneDeep.js?
at InternalError.get (https://nuxt-starter-a2yhjt.w.staticblitz.com/blitz.1f021b18268b32e6c6b2095e039ac8c9f88b0d52.js:6:292488)
at defaultResolve (https://nuxt-starter-a2yhjt.w.staticblitz.com/blitz.1f021b18268b32e6c6b2095e039ac8c9f88b0d52.js:6:622935)
at ESMLoader.resolve (https://nuxt-starter-a2yhjt.w.staticblitz.com/blitz.1f021b18268b32e6c6b2095e039ac8c9f88b0d52.js:6:1210848)
at ESMLoader.getModuleJob (https://nuxt-starter-a2yhjt.w.staticblitz.com/blitz.1f021b18268b32e6c6b2095e039ac8c9f88b0d52.js:6:1208564)
at ESMLoader.import (https://nuxt-starter-a2yhjt.w.staticblitz.com/blitz.1f021b18268b32e6c6b2095e039ac8c9f88b0d52.js:6:1208951)
at importModuleDynamically (https://nuxt-starter-a2yhjt.w.staticblitz.com/blitz.1f021b18268b32e6c6b2095e039ac8c9f88b0d52.js:6:981760)
at i.importModuleDynamicallyCallback (https://nuxt-starter-a2yhjt.w.staticblitz.com/blitz.1f021b18268b32e6c6b2095e039ac8c9f88b0d52.js:6:246238)
at _0x69e4ca (https://nuxt-starter-a2yhjt.w.staticblitz.com/blitz.1f021b18268b32e6c6b2095e039ac8c9f88b0d52.js:15:291665)
at $id_3IjiM7kU2H (file:///home/projects/nuxt-starter-a2yhjt/.nuxt/dist/server/server.mjs:3544:1)
at __instantiateModule__ (file:///home/projects/nuxt-starter-a2yhjt/.nuxt/dist/server/server.mjs:3690:9)
at __ssrLoadModule__ (file:///home/projects/nuxt-starter-a2yhjt/.nuxt/dist/server/server.mjs:3628:25)
at ssrImport (file:///home/projects/nuxt-starter-a2yhjt/.nuxt/dist/server/server.mjs:3653:13)
at $id_jJopoG4kMT (file:///home/projects/nuxt-starter-a2yhjt/.nuxt/dist/server/server.mjs:3383:37)
at async __instantiateModule__ (file:///home/projects/nuxt-starter-a2yhjt/.nuxt/dist/server/server.mjs:3690:3) {
code: 'ERR_MODULE_NOT_FOUND'
}
[nuxt] [request error] [unhandled] [500] [vite dev] Error loading external "lodash/cloneDeep".
at async eval (./.nuxt/dev/index.mjs:117:22)
at async eval (./node_modules/h3/dist/index.mjs:571:19)
at async Server.nodeHandler (./node_modules/h3/dist/index.mjs:517:7)
Issue Analytics
- State:
- Created a year ago
- Reactions:21
- Comments:21 (7 by maintainers)
Top Results From Across the Web
How does JavaScript import find the module without an ...
In a browser with support for ES Modules (ESM), no extensions will be added to the URL that you import - if your...
Read more >ECMAScript modules | Node.js v19.3.0 Documentation
Mandatory file extensions #. A file extension must be provided when using the import keyword to resolve relative or absolute specifiers. Directory indexes...
Read more >Publishing NPM Packages as Native ES Modules - Medium
This is telling babel to replace the strings written to imports, exports, and requires the correct file extension for the module system we...
Read more >import - JavaScript - MDN Web Docs - Mozilla
This is often a relative or absolute URL to the .js file containing the module. In Node, extension-less imports often refer to packages...
Read more >TypeScript and native ESM on Node.js - 2ality
import {start} from 'my-package/dist/src/main.js';. The key point is that, by default, we need to provide filename extensions, especially for ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Resolution: https://stackblitz.com/edit/nuxt-starter-zwu1fk?file=nuxt.config.ts,app.vue build and vite
I’m getting this with
pinia
on rc.8. In my server output when Iyarn build
, it ends up beingimport 'pinia/dist/pinia';
which fails to be able to loadnode_modules/pinia/dist/pina.mjs
.Adding
pinia
totranspile
in the Nuxt configuration doesn’t seem to do anything. I’m guessing there’s something I can do withvite
settings in the Nuxt configuration to get it to explicitly use.mjs
, but I haven’t figured it out yet.