[ERR_REQUIRE_ESM]: Must use import to load module
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 43.3k
- Forks
- 2.7k
- PR merge metrics
- No merged PRs in 30d
Description
What's going wrong?
I am not able to start node application with pm2. The error shown in the log is:
[C:\test\src\index.mjs:1
Error [ERR_REQUIRE_ESM]: Must use import to load module: file:///C:/test/src/index.mjs]
How could we reproduce this issue?
Node v12.18.2
pm2@4.4.0 installed with yarn global add pm2
package.json
{
"name": "test",
"main": "src/index.mjs",
"dependencies": {
"esm": "^3.2.25"
}
}
service.config.js
module.exports = {
/**
* Application configuration section
* http://pm2.keymetrics.io/docs/usage/application-declaration/
*/
apps: [{
name: 'test',
script: './src/index.mjs',
node_args: '-r esm',
watch: false,
}],
}
index.mjs
const startConsuming = async () => {
console.log(1);
}
startConsuming()
export default startConsuming;
$ pm2 report
Start command: pm2 start src/index.mjs --node-args="-r esm"
The app works fine if it's being started with node -r esm src/index.mjs
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the failure with pm2 start src/index.mjs --node-args="-r esm" using the versions and files shown in package.json, service.config.js, and src/index.mjs. Compare it with node -r esm src/index.mjs and trace how PM2 launches the .mjs entry point and passes node_args. Done means the application starts successfully through PM2 without ERR_REQUIRE_ESM.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, node.js
- Domain
- cli, devops
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100