Error run .mjs file
Open
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?
When I run pm2 start index.mjs -e logs/err.log I get an error
PS C:\Users\yuriy\Documents\Projects\testpm2> npm -v
6.13.6
PS C:\Users\yuriy\Documents\Projects\testpm2> node -v
v13.7.0
Error [ERR_REQUIRE_ESM] [ERR_REQUIRE_ESM]: Must use import to load ES Module: C:\Users\yuriy\Documents\Projects\testpm2\index.mjs
at Module.load (internal/modules/cjs/loader.js:998:11)
at Function.Module._load (internal/modules/cjs/loader.js:899:14)
at Object.<anonymous> (C:\Users\yuriy\AppData\Roaming\npm\node_modules\pm2\lib\ProcessContainerFork.js:78:21)
at Module._compile (internal/modules/cjs/loader.js:1151:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1171:10)
at Module.load (internal/modules/cjs/loader.js:1000:32)
at Function.Module._load (internal/modules/cjs/loader.js:899:14)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)
at internal/main/run_main_module.js:17:47
index.mjs
import express from 'express';
const app = express();
const port = 3000;
app.listen(port, () => console.log(`App running on port + ${port}`));
package.json
{
"name": "testpm2",
"version": "1.0.0",
"engines": {
"node": ">=13.0.0"
},
"description": "",
"main": "index.mjs",
"type": "module",
"scripts": {},
"repository": {
"type": "git",
"url": "git+https://github.com/YuriyTigiev/testpm2.git"
},
"keywords": [],
"author": "",
"license": "ISC",
"bugs": {
"url": "https://github.com/YuriyTigiev/testpm2/issues"
},
"homepage": "https://github.com/YuriyTigiev/testpm2#readme",
"devDependencies": {
"cross-env": "^6.0.3",
"eslint": "^6.8.0",
"eslint-config-standard": "^14.1.0",
"eslint-plugin-import": "^2.20.0",
"eslint-plugin-node": "^11.0.0",
"eslint-plugin-promise": "^4.2.1",
"eslint-plugin-standard": "^4.0.1"
},
"dependencies": {
"dotenv": "^8.2.0",
"express": "^4.17.1",
"module-js": "^7.0.1"
}
}
ecosystem.config.mjs
export const apps = [
{
name: 'myapp',
script: './index.mjs',
watch: true,
env: {
'PORT': 3000,
'NODE_ENV': 'development'
}
}
];
How could we reproduce this issue?
$ pm2 report
pm2 report doesn't work on windows 10


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 with the provided index.mjs, package.json, and ecosystem.config.mjs using pm2 start index.mjs -e logs/err.log on the reported Node.js version. Start at lib/ProcessContainerFork.js:78 from the stack trace and compare the direct and ecosystem launch paths. Done means the .mjs entry point starts without ERR_REQUIRE_ESM; separately verify the reported pm2 report behavior on Windows 10.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- express, javascript, node.js
- Domain
- backend, cli
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100