serve icon indicating copy to clipboard operation
serve copied to clipboard

PM2 treats serve like a CommonJS Module

Open mono424 opened this issue 2 years ago • 2 comments

Description

I ran into the problem that PM2 thinks the package is not a es-module package even-tough it is. So I am getting Error [ERR_REQUIRE_ESM]: Must use import to load ES Module:

After some investigation I found out that pm2 loads the serve package from [...]/node/v14.20.0/bin. Its a binary and there is no package-json so PM2 fails to categorize.

Is there any way to fix this from the "serve"-side.

Thanks :)

Library version

14.0.1

Node version

v14.20.0

mono424 avatar Aug 18 '22 18:08 mono424

Same issue

Porqumn avatar Sep 08 '22 06:09 Porqumn

my workaround is to change working directory to where the package.json locates, then run the pm2 command.

$ file $(which serve)
/usr/local/bin/serve: symbolic link to ../lib/node_modules/serve/build/main.js
$ cd /usr/local/lib/node_modules/serve
$ pm2 start build/main.js

pseudocc avatar Sep 30 '22 05:09 pseudocc