PM2 Startup Error with Node and Typescript

ᎣᏏᏲ. ᏙᎯᏧ? Hey, welcome back!

If you decide to run PM2 to run your node server and you’re using Typescript you can get this error:

[PM2][ERROR] Interpreter .nvm/versions/node/v18.11.0/lib/node_modules/pm2/node_modules/.bin/ts-node is NOT AVAILABLE in PATH. (type ‘which .nvm/versions/node/v18.11.0/lib/node_modules/pm2/node_modules/.bin/ts-node’ to double check.)

It can come in many forms but the important part is ts-node is NOT AVAILABLE in PATH.

The fix for this is to go to where you’re version of node is (and in this case it tells me it’s at: .nvm/versions/node/v18.11.0/lib/node_modules/pm2/node_modules/.bin/ts-node

From your CLI cd into the path it shows to pm2 – in this case for me – .nvm/versions/node/v18.11.0/lib/node_modules/pm2

Your command will look like this: ./bin/pm2 install typescript

The CLI/Terminal will give you some text that tells you it’s installed – this is what mine looks like:

/home/winkdoubleguns/.nvm/versions/node/v18.11.0/lib/node_modules/pm2/bin/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! syscall rename
npm ERR! path /home/winkdoubleguns/.nvm/versions/node/v18.11.0/lib/node_modules/pm2/node_modules/@pm2/pm2-version-check
npm ERR! dest /home/winkdoubleguns/.nvm/versions/node/v18.11.0/lib/node_modules/pm2/node_modules/@pm2/.pm2-version-check-kBAffvLe
npm ERR! errno -39
npm ERR! ENOTEMPTY: directory not empty, rename '/home/winkdoubleguns/.nvm/versions/node/v18.11.0/lib/node_modules/pm2/node_modules/@pm2/pm2-version-check' -> '/home/winkdoubleguns/.nvm/versions/node/v18.11.0/lib/node_modules/pm2/node_modules/@pm2/.pm2-version-check-kBAffvLe'

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/winkdoubleguns/.npm/_logs/2022-11-01T12_41_11_112Z-debug-0.log
[PM2][Module] No configuraton script found.

added 57 packages, changed 1 package, and audited 241 packages in 5s

27 packages are looking for funding
  run `npm fund` for details

found 0 vulnerabilities
[PM2][Module] No configuraton script found.
[PM2] typescript ENABLED
[PM2] ts-node@latest ENABLED
│ id │ name               │ mode     │ ↺    │ status    │ cpu      │ memory   │
[PM2][WARN] Current process list is not synchronized with saved list. App index differs. Type 'pm2 save' to synchronize.

After that’s complete you can go back to your server and run pm2 start index.ts and the server should start right up.

Until next time. Dodadagohvi. ᏙᏓᏓᎪᎲᎢ.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: