I found issue #3751 and tried to use esm module instead of --experimental-modules option. It works fine. I will use it now. But it is workaround. It would be nice if the --experimental-modules option worked too (in the example I pushed to GitHub above).
Thank you.
The --experimental-modules flag works with pm2, but it doesn't take "type": "module" from package.json into account.
Example code:
// foo.js
export const foo = "bar";
// index.js
import { foo } from './foo.js';
console.log(foo)
// package.json
{
"type": "module"
}
Running with node directly:
$ node -v
v12.6.0
$ node --experimental-modules index.js
(node:11912) ExperimentalWarning: The ESM module loader is experimental.
bar
Running with pm2:
$ pm2 --version
3.5.1
$ pm2 start index.js --node-args="--experimental-modules"
$ pm2 logs index --raw --err
(node:9712) ExperimentalWarning: The ESM module loader is experimental.
E:\GitHub\pm2-test\index.js:1
import { foo } from './foo.js';
^
SyntaxError: Unexpected token {
at Module._compile (internal/modules/cjs/loader.js:720:23)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:787:10)
at Module.load (internal/modules/cjs/loader.js:643:32)
at Proxy.Module._load (internal/modules/cjs/loader.js:556:12)
at Object.<anonymous> (C:\Users\[REDACTED]]\v12.6.0\node_modules\pm2\lib\ProcessContainerFork.js:27:21)
at Module._compile (internal/modules/cjs/loader.js:776:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:787:10)
at Module.load (internal/modules/cjs/loader.js:643:32)
at Function.Module._load (internal/modules/cjs/loader.js:556:12)
at internal/modules/esm/translators.js:87:15
Thank you, @sidvishnoi. How can I solve it? I see node hasn't --type parameter.
How can I solve it?
No idea. I'm reporting to support this issue to be fixed.
I see node hasn't --type parameter
Yes, there isn't. It has to be fixed at pm2 level.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
Most helpful comment
No idea. I'm reporting to support this issue to be fixed.
Yes, there isn't. It has to be fixed at pm2 level.