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:
-
In pages/index.js:
import { A } from '../config.mjs';
export default function IndexPage() {
return A;
}
-
In Terminal, run:
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:
#13076
Bug report
Describe the bug
Importing a project ESM
.mjsfile (the Node.js standard file extension for ESM) in a page file causes a runtime error, but only in dev mode: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.mjsfile containing:In
pages/index.js:In Terminal, run:
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
.mjsfiles in your Next.js project without runtime errors in dev mode.System information
Additional context
Other Next.js users have also encountered this issue:
#13076