-
Notifications
You must be signed in to change notification settings - Fork 29.4k
Closed
Labels
WebpackRelated to Webpack with Next.js.Related to Webpack with Next.js.good first issueEasy to fix issues, good for newcomersEasy to fix issues, good for newcomerslocked
Description
Bug report
Describe the bug
Importing a project ESM .mjs
file (the Node.js standard file extension for ESM) in a page file causes a runtime error, but only in dev mode:
Unhandled Runtime Error
ReferenceError: module is not defined
Here is the call stack:
To Reproduce
Steps to reproduce the behavior, please provide code snippets or a repository:
-
Create a basic Next.js project.
-
Create a
config.mjs
file containing:export const A = 'a';
-
In
pages/index.js
:import { A } from '../config.mjs'; export default function IndexPage() { return A; }
-
In Terminal, run:
npm run dev
You should then see no error in Terminal, but on the client you will see the Next.js error overlay with the error described earlier.
Expected behavior
You should be able to use ESM .mjs
files in your Next.js project without runtime errors in dev mode.
System information
- Version of Next.js: v9.5.5
Additional context
Other Next.js users have also encountered this issue:
krothenbaum, ianwalter, longtc, GTOsss, 7iomka and 26 more
Metadata
Metadata
Assignees
Labels
WebpackRelated to Webpack with Next.js.Related to Webpack with Next.js.good first issueEasy to fix issues, good for newcomersEasy to fix issues, good for newcomerslocked