-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
support "type": "module" (esm for node 13) #4540
Comments
Some investigations: (node v13.3.0, pm2 4.2.0, MacOs 10.14.6)
The only workaround I've found so far is to keep esm is to use ESM loader with node args: related to [https://github.com//issues/4385] NB: There is absolutely no require() in the code |
Same here. I'm using .mjs and node 13, but esm workaround not even working for me. App runs fine using systemd daemon. |
This is my first time using pm2 and I thought I was going insane! Have been googling about this for hours. I hope there will be a fix soon |
A quick and dirty fix for pm2/lib/ProcessContainerFork.js : @Unitech
Workaround: We need to use node interpreter args:
|
Thanks for this report and suggestion, will dig this |
Is this seriously not working? |
@Unitech how can I help? This is pretty critical for my team as we're using modules in production. It's been enabled officially by node, although still experimental (it works great on my end) |
@Unitech Plz comment, this has been out for some time now and it has not been addressed |
Will work on it by the next 7 days |
Thanks, I've had to resort to using |
Ok I landed the ES module support |
Can anyone try it out please?
Thank you! |
I've checked:
|
Works for me, but I had an error with this applying to saved processes. I had to delete the process from pm2 and then reinstall it for it to work. Not a huge deal, but it might affect users wanting to move over to ESM |
Release on pm2 4.2.2
|
It works ! thanks a lot |
Just a detail: according to Node.js doc: https://nodejs.org/api/esm.html
Here pm2 is checking package.json in the current folder and it's first parent. |
with ESM on windows my success only with:
|
This does not work with the docker RUN yarn global add pm2@4.2.2
COPY . .
EXPOSE 8080
CMD [ "pm2-runtime", "index.js" ] Gives:
adding Per @vitaliytv suggestion I chcnged the following. CMD [ "pm2-runtime", " node -- index.js" ] |
Having issues with this again |
@Unitech I'm getting |
This is what worked for me, since the |
What worked for me to make it run with ecosystem config was naming it ecosystem.config.cjs, and starting with |
I'll echo @EskelCz in that renaming your ecoystem file to end with |
This worked for me, thank you so much! |
@Unitech Any updates with I changed the config name to pm2 start ecosystem.config.cjs |
module.exports = {
apps : [{
name : "API",
script : "./src/Admin/API/Index.js"
}]
} Throws the same error - Ive had to go back to nodemon :( |
esm is natively supported, stable in all active LTS distributions. Is this not something pm2 ever plans to support? |
Working for me with a package.json inside the route.
|
Has the problem been solved? |
Yes the problem is solved. This solution worked for me.
чт, 6 янв. 2022 г., 17:35 Ramsay Jiang ***@***.***>:
… @Unitech <https://github.com/Unitech> Any updates with node 14 I am using pm2
v5 and still have the same problem.
I changed the config name to ecosystem.config.cjs then
pm2 start ecosystem.config.cjs
Has the problem been solved?
—
Reply to this email directly, view it on GitHub
<#4540 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AFMLXHTVTJ7LOWNYJTMJIL3UUWSEDANCNFSM4JVW4OYA>
.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>.
You are receiving this because you are subscribed to this thread.Message
ID: ***@***.***>
|
I still get many errors, I use node 17.3, pm2 5.1.2 and ESM... |
Yup, same here. EDIT: solved using exosystem.config file with CJS extension as mentioned in some posts above |
I think this comment should get a prize:
Thank you so much, @adamhl8 ! |
Ok, so This ecosystem.config.js doesn't work in this case, yet it's all you see in the docs:
But this ecosystem.config.json works:
Also this ecosystem.config.yaml works:
If you really want to stick with a JS file, this ecosystem.config.es6.js works as well:
I'm not saying the docs are bad, but they certainly don't cover every new kind of possibility. Bonus:
Probably the easisest json config if you only have 1 app to config and have managed by pm2. |
2 and a half year with no luck? That's a shame :( Anyway, the simplest solution is the one from @nickpharrison Near your index.js or whatever create |
I was starting to think that pm2 is superfluous. You can better manage
integrating directly with systemd
Il ven 3 giu 2022, 21:33 Jacek Nowacki ***@***.***> ha
scritto:
… 2 and a half year with no luck? That's a shame :(
Anyway, the simplest solution is the one from @nickpharrison
<https://github.com/nickpharrison>
Near your index.js or whatever create entry.mjs file with import
"./index.js" and run it instead. It just works, the .mjs extension is
what forces node into ESM mode.
—
Reply to this email directly, view it on GitHub
<#4540 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AADXQ34KTVHWV4LLLPHHCTLVNJMW3ANCNFSM4JVW4OYA>
.
You are receiving this because you commented.Message ID:
***@***.***>
|
100% agreed, pm2 (and other service wrappers) aren't needed in 2022. |
Things get even weirder if one is trying to use Unlike what @Firsh mentions, the Also, using an var defaultConfigNames = ['ecosystem.config.js', 'ecosystem.json', 'ecosystem.json5', 'package.json']; So, clearly, those are the only file names allowed. Also, any of them will by parsed (by calling Common.parseConfig()) and end up being required, which is, needless to say, very frustrating if your entire project is using ES6 modules — in other words, as far as I can tell, the only way to use
where It would be nice if pm2 caught that automatically, which, it now occurs to me, would just require adding @@ -67,7 +67,7 @@ module.exports = function(CLI) {
// Find ecosystem file by default
if (!Common.isConfigFile(file)) {
env = args[0];
- var defaultConfigNames = ['ecosystem.config.js', 'ecosystem.json', 'ecosystem.json5', 'package.json'];
+ var defaultConfigNames = ['ecosystem.config.js', 'ecosystem.config.cjs', 'ecosystem.json', 'ecosystem.json5', 'package.json'];
file = Utility.whichFileExists(defaultConfigNames);
if (!file) { |
@rhwinter - Agreed, it would be nice if they added ecosystem.config.cjs. I had this exact same issue a week ago and like you said you have to manually specify ecosystem.config.cjs on the command line. It sure would be nice if they added cjs as well. Can you create a pull request? |
Wow, I couldn't solve this for 2 weeks, but now it's done. |
If you are here scratching your head and pulling whatever hairs you have left there... :) |
Searching for this issue brought me here. Trying to run pm2 on a Debian 11 Linode instance - ran into issues. I had installed node with |
There is an example above illustrated by @Firsh that uses a export default {
apps: [
{
name: 'foo',
script: 'node foo.js',
},
{
name: 'bar',
script: 'node bar.js',
}
]
};
console.log("hello"); The |
It looks like in 5.3.1 this issue was solved for ecosystem.config.cjs Here is the commit c810b9f If that is the case i think you can use We could probably close this issue? |
This was the solution to my problem!! Thank you Uritz!! |
esm is no longer experimental in node 13, however pm2 does not read out
"type": "module"
frompackage.json
, which means that esm imports/exports can not be used with pm2:The text was updated successfully, but these errors were encountered: