Pm2: Interpreter ts-node doest not seem to be available when using package.json script

Created on 26 Nov 2017  ยท  8Comments  ยท  Source: Unitech/pm2

I'm not sure if my issue is the same as #2742 since I only get the error when using pm2 in package.json.

What's going wrong?

I have this script in my package.json:

"start": "pm2 start src/server.ts --watch"

and when I

yarn start

I get the error

Interpreter /home/.../.bin/ts-node does not seem to be available

and the process status is 'errored'.

But when I run the pm2 command in the shell it works fine.

How could we reproduce this issue?

  • Create a simple node.js typescript project
  • pm2 install typescript
  • Add the script in the package.json
  • npm/yarn start

Supporting information

===============================================================================
--- PM2 REPORT (Sun Dec 03 2017 13:33:33 GMT+0100 (CET)) ----------------------
===============================================================================
--- Daemon -------------------------------------------------
pm2d version         : 2.8.0
node version         : 8.8.1
node path            : /usr/bin/pm2
argv                 : /usr/bin/node,/usr/lib/node_modules/pm2/lib/Daemon.js
argv0                : node
user                 : greg
uid                  : 1000
gid                  : 100
uptime               : 1min
===============================================================================
--- CLI ----------------------------------------------------
local pm2            : 2.8.0
node version         : 8.8.1
node path            : /usr/bin/pm2
argv                 : /usr/bin/node,/usr/bin/pm2,report
argv0                : node
user                 : greg
uid                  : 1000
gid                  : 100
===============================================================================
--- System info --------------------------------------------
arch                 : x64
platform             : linux
type                 : Linux
cpus                 : Intel(R) Core(TM) i5-7200U CPU @ 2.50GHz
cpus nb              : 4
freemem              : 3863879680
totalmem             : 8255234048
home                 : /home/greg
===============================================================================
--- PM2 list -----------------------------------------------
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ App name โ”‚ id โ”‚ mode โ”‚ pid โ”‚ status  โ”‚ restart โ”‚ uptime โ”‚ cpu โ”‚ mem    โ”‚ user โ”‚ watching โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ server   โ”‚ 0  โ”‚ fork โ”‚ N/A โ”‚ errored โ”‚ 0       โ”‚ 0      โ”‚ 0%  โ”‚ 0 B    โ”‚ greg โ”‚ enabled  โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
===============================================================================
--- Daemon logs --------------------------------------------
/home/greg/.pm2/pm2.log last 20 lines:
PM2        | 2017-12-03 13:32:24: [Watch] Start watching server
PM2        | 2017-12-03 13:32:24: Starting execution sequence in -fork mode- for app name:server id:0
PM2        | 2017-12-03 13:32:24: App name:server id:0 online
PM2        | 2017-12-03 13:32:24: Error: spawn /home/greg/Documents/pm2-bug/node_modules/pm2/node_modules/.bin/ts-node ENOENT
PM2        |     at _errnoException (util.js:1024:11)
PM2        |     at Process.ChildProcess._handle.onexit (internal/child_process.js:192:19)
PM2        |     at onErrorNT (internal/child_process.js:374:16)
PM2        |     at _combinedTickCallback (internal/process/next_tick.js:138:11)
PM2        |     at process._tickDomainCallback (internal/process/next_tick.js:218:9)

Most helpful comment

I was facing exact same error. Problem was confusion between global pm2 with local pm2 installed in node_modules of my project. So I had to do
./node_modules/.bin/pm2 install typescript and NOT pm2 install typescript to solve it.

Also that involves using ./node_modules/.bin/pm2 start src/server.ts --watch in your start script in package.json.

All 8 comments

I was facing exact same error. Problem was confusion between global pm2 with local pm2 installed in node_modules of my project. So I had to do
./node_modules/.bin/pm2 install typescript and NOT pm2 install typescript to solve it.

Also that involves using ./node_modules/.bin/pm2 start src/server.ts --watch in your start script in package.json.

Thanks, it works !

I added the script "postinstall": "$(yarn bin)/pm2 install typecsript" to my package.json

@verdie-g Small mistake on your command.

Use:

"postinstall": "$(yarn bin)/pm2 install typescript"

I have an issue trying to install typescript for pm2. This is what I get:

# pm2 install typescript
[PM2][Module] Adding dependency typescript to PM2 Runtime
[PM2][Module] Calling [NPM] to install typescript ...
[PM2][Module] Calling [NPM] to install ts-node@latest ...
โ–„ โ•ขโ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ•Ÿ
npm ERR! Linux 4.15.0-50-generic
npm ERR! argv "/usr/bin/node" "/usr/bin/npm" "install" "ts-node@latest" "--loglevel=error"
npm ERR! node v8.10.0
npm ERR! npm  v3.5.2

npm ERR! Cannot read property 'target' of null
npm ERR! 
npm ERR! If you need help, you may report this error at:
loadDep:has-values        โ– โ•ขโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ•Ÿ

npm ERR! Please include the following file with any support request:
npm ERR!     /usr/local/lib/node_modules/pm2/npm-debug.log
npm ERR! Linux 4.15.0-50-generic
npm ERR! argv "/usr/bin/node" "/usr/bin/npm" "install" "typescript" "--loglevel=error"
npm ERR! node v8.10.0
npm ERR! npm  v3.5.2

npm ERR! Cannot read property 'target' of null
npm ERR! 
npm ERR! If you need help, you may report this error at:
npm ERR!     <https://github.com/npm/npm/issues>

npm ERR! Please include the following file with any support request:
npm ERR!     /usr/local/lib/node_modules/pm2/npm-debug.log

I've configured pm2 at the machine level and with configuration and I can't use the application node_modules pm2.

I fixed by removing all the pm2 and ts-node from the package.json and make sure you don't run the below commands again and again

sudo pm2 install typescript
sudo pm2 install @types/node

More than once, verify by checking if /usr/lib/node_modules/pm2/node_modules/.bin is having ts-node, if it exist don't install typescript and @types/node.

Freaking annoying issue. It's still there in 2020.

@akopchinskiy try to above solution, I've spent 3 days to figure this solution out.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

rajendar38 picture rajendar38  ยท  3Comments

shaunwarman picture shaunwarman  ยท  3Comments

webchaz picture webchaz  ยท  3Comments

ldarren picture ldarren  ยท  3Comments

morfies picture morfies  ยท  3Comments