You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When we define the script param, PM2 have to identify if this file it's an ESModule or CommonJS, to do so, it tries to find the package.json from the current directory of the script. If it's not there, it will check on the parent one. (ProcessUtils.js).
If the file is located, It will look for the { type: "module" } property, so If it's a "module" then it loads as an ESModule otherwise, will be loaded as a CommonJS module
Problem:
If we have different folder structure something like
PM2 will be unable to find the package.json unless we move the script into src or project folder.
How could we reproduce this issue?
I created a CodeSandbox.
In a new terminal, you can run any of the following commands
npm run start1: This will be able to run the server, locating correctly the package.json
npm run start2: This will not be able to run the server, because pm2 is unable to locate correctly the package.json and will understand server.js as a CommonJS instead of a ESModule.
Supporting information
Using .mjs extension will identify the module correctly, but the Node Specification also accepts this approach Files ending in .js when the nearest parent package.json file contains a top-level "type" field with a value of "module".
The text was updated successfully, but these errors were encountered:
What's going wrong?
Context:
When we define the
script
param, PM2 have to identify if this file it's an ESModule or CommonJS, to do so, it tries to find thepackage.json
from the current directory of thescript
. If it's not there, it will check on the parent one. (ProcessUtils.js).If the file is located, It will look for the
{ type: "module" }
property, so If it's a "module" then it loads as an ESModule otherwise, will be loaded as a CommonJS moduleProblem:
If we have different folder structure something like
PM2 will be unable to find the
package.json
unless we move the script intosrc
orproject
folder.How could we reproduce this issue?
I created a CodeSandbox.
In a new terminal, you can run any of the following commands
npm run start1
: This will be able to run the server, locating correctly the package.jsonnpm run start2
: This will not be able to run the server, because pm2 is unable to locate correctly the package.json and will understandserver.js
as a CommonJS instead of a ESModule.Supporting information
Using
.mjs
extension will identify the module correctly, but the Node Specification also accepts this approach Files ending in .js when the nearest parent package.json file contains a top-level "type" field with a value of "module".The text was updated successfully, but these errors were encountered: