asdf-nodejs icon indicating copy to clipboard operation
asdf-nodejs copied to clipboard

Unexpected identifier pipefail

Open donncha opened this issue 3 years ago • 1 comments

Any ideas what's causing "Unexpected identifier" for pipefail??

$ asdf plugin add nodejs
$ asdf install nodejs 16.14.2
$ asdf global nodejs 16.14.2
$ npm install pm2 -g
$ asdf reshim
$ pm2 start ecosystem.json
$ pm2 status
... shows "errored"
$  pm2 logs API-Gateway

0|API-Gate | /Users/donncha/.asdf/plugins/nodejs/shims/npm:4
0|API-Gate | set -o pipefail
0|API-Gate |        ^^^^^^^^
0|API-Gate |
0|API-Gate | SyntaxError: Unexpected identifier
0|API-Gate |     at Object.compileFunction (node:vm:352:18)
0|API-Gate |     at wrapSafe (node:internal/modules/cjs/loader:1031:15)
0|API-Gate |     at Module._compile (node:internal/modules/cjs/loader:1065:27)
0|API-Gate |     at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
0|API-Gate |     at Module.load (node:internal/modules/cjs/loader:981:32)
0|API-Gate |     at Function.Module._load (node:internal/modules/cjs/loader:822:12)
0|API-Gate |     at Object.<anonymous> (/Users/donncha/.config/yarn/global/node_modules/pm2/lib/ProcessContainerFork.js:33:23)
0|API-Gate |     at Module._compile (node:internal/modules/cjs/loader:1101:14)
0|API-Gate |     at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
0|API-Gate |     at Module.load (node:internal/modules/cjs/loader:981:32)

I'm using asdf for ruby & node. Another team who are JS only ran into the same problem above with asdf so switched to nvm and have no issues.

OS: OSX 12.6, 16" M1 Macbook Pro ASDF: 0.10.2 NPM: 8.5.0 Yarn: 1.22.17

The relevant app definition in ecosystem.json is

    {
      "name": "API-Gateway",
      "script": "npm",
      "args": "run dev",
      "cwd": "./API-Gateway"
    },

donncha avatar Oct 12 '22 23:10 donncha

I've since removed the asdf-nodejs plugin and everything is working perfectly with just nvm.

donncha avatar Oct 13 '22 21:10 donncha

This is a compatibility problem with pm2, it expects npm to be a node.js script, instead of a shim. nvm works because it doesn't rely on shims for managing node versions, a strategy with its own pros and cons.

For anyone reaching the same error, before running pm2 try setting the PATH variable to point to real npm command before running it.

env PATH="$(asdf where nodejs)/bin:$PATH" pm2 ...

To have a proper fix for this, pm2 would need to expect npm as a generic executable instead of a nodejs script, it would need to be fixed upstream. If not supported on newer versions already

augustobmoura avatar Jun 27 '23 15:06 augustobmoura