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

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)
6 Answers

✔️Accepted Answer

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.

More Issues: