Skip to content

Support for ES6 modules #787

@jcalfee

Description

@jcalfee

Environment

nuxt@2.16.3
nuxt dev
node v18

Reproduction

Install per the README and add "type": "module" to package.json. Make an http page request..

Describe the bug

Startup and make a page request. The first page request shows an error that suggests that the nuxt bridge is compiling to commonjs code even thought the package is a module.

Additional context

No response

Logs

[web] New request: http://code.local:3000/
[web] [nuxt] [request error] [unhandled] [500] require() of ES Module /home/project/resp-val/.nuxt/dist/server/server.js not supported.
[web] server.js is treated as an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which declares all .js files in that package scope as ES modules.
[web] Instead rename server.js to end in .cjs, change the requiring code to use dynamic import() which is available in all CommonJS modules, or change "type": "module" to "type": "commonjs" in /home/project/resp-val/package.json to treat all .js files as CommonJS (using .mjs for all ES modules instead).

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions