Skip to content
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

PM2 unable to run ESM packages: ERR_UNSUPPORTED_ESM_URL_SCHEME #4839

Closed
ox-harris opened this issue Sep 4, 2020 · 5 comments
Closed

PM2 unable to run ESM packages: ERR_UNSUPPORTED_ESM_URL_SCHEME #4839

ox-harris opened this issue Sep 4, 2020 · 5 comments

Comments

@ox-harris
Copy link
Contributor

What's going wrong?

In this version of pm2 (v4.4.1), pm2.start ('reference/to/esm-package/script.js') is throwing the following error in err.log file: Error [ERR_UNSUPPORTED_ESM_URL_SCHEME]: Only file and data URLs are supported by the default ESM loader

The stack trace reveals the problem to be with the ESM script loader in lib\ProcessContainerFork.js:29:24. There the import statement is attempting to import the ESM script using the file path instead of a file scheme.

How could we reproduce this issue?

Try starting a script within an ES module package: pm2.start ('reference/to/esm-package/script.js'), then find the error in the err file for the process.

Supporting information

PM2 version: v4.4.1
Node version: v13.7.0
OS: windows

I wouldn't mind submitting a PR for a fix. It simply requires converting the given path to a file URL using url.pathToFileURL().
So, instead of import(process.env.pm_exec_path);, we should now have import(url.pathToFileURL(process.env.pm_exec_path));

@Unitech
Copy link
Owner

Unitech commented Sep 29, 2020

published in pm2@4.5.0

npm install pm2@latest -g

@Unitech Unitech closed this as completed Sep 29, 2020
@ParallelUniv3rse
Copy link

ParallelUniv3rse commented Dec 10, 2020

Hi @ox-harris,
still having trouble with this when running basic pm2 start ecosystem.json on windows in cluster mode.
I've tried switching to fork mode, but no luck there either. Process is still using ProcessContainer.js where this same exact issue occurs on line 301.

Any special steps on how to make use of this fix?

EDIT: Nevermind, fork mode works, that was just me reading the logs wrong, but the problem in ProcessContainer.js:301 still stands - cluster mode does not work.

mendrix pushed a commit to mendrix/pm2 that referenced this issue Dec 29, 2020
@pubmikeb
Copy link

@Unitech, unfortunately this issue is still relevant for pm2 v.5.1.0 running on Node.js 16.4.0.
Currently, I can't use "exec_mode": "cluster", only "exec_mode": "fork" can be used.

Please, fix the incompatibility to be able use the full potential of pm2.

@aramis-it
Copy link

aramis-it commented Jul 23, 2021

Same problem with cluster mode v5.1.0 Node 16.5 Windows 10
Are there any solutions?

@rujiel
Copy link

rujiel commented Oct 25, 2021

I was experiencing this error being thrown from another file, ProcessContainer.js, but my workaround was to look for the usage of "process.env.pm_exec_path" that it is choking on in the pm2 library files, and it replace it with the string path to your script. It will auto-append your drive letter, so just start the path with a slash. i.e.

import(process.env.pm_exec_path);
-->
import('/Users/you/script.mjs');

Just be sure to remember to revert the pm2 change you've made! Or that could get confusing real fast.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants