Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to use TypeScript #2742

Closed
MickL opened this issue Mar 1, 2017 · 25 comments
Closed

Unable to use TypeScript #2742

MickL opened this issue Mar 1, 2017 · 25 comments

Comments

@MickL
Copy link

MickL commented Mar 1, 2017

Expected behaviour

pm2 start x.ts should work. (Maybe TypeScript should be installed on default so everything works out of the box)

Actual behaviour

I was not able to start a ts file. js works fine.

Both ts-node and index have status "errored"

pm2 list:
bildschirmfoto 2017-03-01 um 16 45 24

I did pm2 install typescript and pm2 install node-ts

Here is the log:
bildschirmfoto 2017-03-01 um 16 47 59

When i try: pm2 install @types/node it says:

Error: Cannot find module '/home/mick/.pm2/node_modules/node/package.json'
    at Function.Module._resolveFilename (module.js:470:15)
    at Function.Module._load (module.js:418:25)
    at Module.require (module.js:498:17)
    at require (internal/module.js:20:19)
    at startModule (/usr/lib/node_modules/pm2/lib/API/Modules/Modularizer.js:33:22)
    at /usr/lib/node_modules/pm2/lib/API/Modules/Modularizer.js:158:9
    at /usr/lib/node_modules/pm2/lib/Configuration.js:64:14
    at FSReqWrap.oncomplete (fs.js:114:15)

Software versions used

OS         : Ubuntu Server 16.04.2 LTS
node.js    : v7.6.0
PM2        : 2.4.2

PM2 Log output

2017-03-01 07:42:02: App [index] with id [1] and pid [50857], exited with code [1] via signal [SIGINT]
2017-03-01 07:42:02: Starting execution sequence in -fork mode- for app name:index id:1
2017-03-01 07:42:02: App name:index id:1 online
2017-03-01 07:42:03: App [index] with id [1] and pid [50889], exited with code [1] via signal [SIGINT]
2017-03-01 07:42:03: Starting execution sequence in -fork mode- for app name:index id:1
2017-03-01 07:42:03: App name:index id:1 online
2017-03-01 07:42:03: App [index] with id [1] and pid [50921], exited with code [1] via signal [SIGINT]
2017-03-01 07:42:03: Starting execution sequence in -fork mode- for app name:index id:1
2017-03-01 07:42:03: App name:index id:1 online
2017-03-01 07:42:04: App [index] with id [1] and pid [50953], exited with code [1] via signal [SIGINT]
2017-03-01 07:42:04: Starting execution sequence in -fork mode- for app name:index id:1
2017-03-01 07:42:04: App name:index id:1 online
2017-03-01 07:42:05: App [index] with id [1] and pid [50985], exited with code [1] via signal [SIGINT]
2017-03-01 07:42:05: Starting execution sequence in -fork mode- for app name:index id:1
2017-03-01 07:42:05: App name:index id:1 online
2017-03-01 07:42:06: App [index] with id [1] and pid [51027], exited with code [1] via signal [SIGINT]
2017-03-01 07:42:06: Starting execution sequence in -fork mode- for app name:index id:1
2017-03-01 07:42:06: App name:index id:1 online
2017-03-01 07:42:07: App [index] with id [1] and pid [51059], exited with code [1] via signal [SIGINT]
2017-03-01 07:42:07: Starting execution sequence in -fork mode- for app name:index id:1
2017-03-01 07:42:07: App name:index id:1 online
2017-03-01 07:42:08: App [index] with id [1] and pid [51091], exited with code [1] via signal [SIGINT]
2017-03-01 07:42:08: Starting execution sequence in -fork mode- for app name:index id:1
2017-03-01 07:42:08: App name:index id:1 online
2017-03-01 07:42:08: App [index] with id [1] and pid [51123], exited with code [1] via signal [SIGINT]
2017-03-01 07:42:08: Starting execution sequence in -fork mode- for app name:index id:1
2017-03-01 07:42:08: App name:index id:1 online
2017-03-01 07:42:09: App [index] with id [1] and pid [51155], exited with code [1] via signal [SIGINT]
2017-03-01 07:42:09: Starting execution sequence in -fork mode- for app name:index id:1
2017-03-01 07:42:09: App name:index id:1 online
2017-03-01 07:42:10: App [index] with id [1] and pid [51187], exited with code [1] via signal [SIGINT]
2017-03-01 07:42:10: Starting execution sequence in -fork mode- for app name:index id:1
2017-03-01 07:42:10: App name:index id:1 online
2017-03-01 07:42:11: App [index] with id [1] and pid [51219], exited with code [1] via signal [SIGINT]
2017-03-01 07:42:11: Starting execution sequence in -fork mode- for app name:index id:1
2017-03-01 07:42:11: App name:index id:1 online
2017-03-01 07:42:11: App [index] with id [1] and pid [51251], exited with code [1] via signal [SIGINT]
2017-03-01 07:42:11: Starting execution sequence in -fork mode- for app name:index id:1
2017-03-01 07:42:11: App name:index id:1 online
2017-03-01 07:42:12: App [index] with id [1] and pid [51283], exited with code [1] via signal [SIGINT]
2017-03-01 07:42:12: Starting execution sequence in -fork mode- for app name:index id:1
2017-03-01 07:42:12: App name:index id:1 online
2017-03-01 07:42:13: App [index] with id [1] and pid [51315], exited with code [1] via signal [SIGINT]
2017-03-01 07:42:13: Starting execution sequence in -fork mode- for app name:index id:1
2017-03-01 07:42:13: App name:index id:1 online
2017-03-01 07:42:14: App [index] with id [1] and pid [51347], exited with code [1] via signal [SIGINT]
2017-03-01 07:42:14: Starting execution sequence in -fork mode- for app name:index id:1
2017-03-01 07:42:14: App name:index id:1 online
2017-03-01 07:42:15: App [index] with id [1] and pid [51379], exited with code [1] via signal [SIGINT]
2017-03-01 07:42:15: Script /home/mick/opnsrc/server/index.ts had too many unstable restarts (16). Stopped. "errored"
@vmarchaud
Copy link
Contributor

vmarchaud commented Mar 1, 2017

Because you need to install the ts-node module to interpret typescript, we made an alias so when you just run pm2 install typescript, it install ts-node where we need it.

@MickL
Copy link
Author

MickL commented Mar 1, 2017

As i described above i did install typescript with pm2 install typescript.

@vmarchaud vmarchaud reopened this Mar 1, 2017
@vmarchaud
Copy link
Contributor

Are you sure that your app is working outside PM2, from your second screen we can see an error : Unable to compile to typescript

@MickL
Copy link
Author

MickL commented Mar 1, 2017

Seems like ts-node cant find typescript. Not sure why TypeScript compiler is running anyway, but it cant find the definition files. And as i described above i was not able to install them by pm2 install @types/node

@vmarchaud
Copy link
Contributor

Because they aren't installed at the same place, there is a custom logic for transpiler, is ts-node not standalone anymore ?

@MickL
Copy link
Author

MickL commented Mar 1, 2017

I don't know i tried reinstalling everything several times. Can someone reproduce?

@MickL
Copy link
Author

MickL commented Mar 1, 2017

This could be a TypeScript or npm issue: TypeScript requires alot of devDependencies e.g. the needed @types/node but none of them gets installed neither global or in pm2.

I tried global node-ts and tsc and both had the same error. I downgraded to nodejs 6.10.0 and it worked. Still the error persists for pm2.

@vmarchaud
Copy link
Contributor

vmarchaud commented Mar 1, 2017

Could you list me exactly what need to be installed (the minimum) to run a typescript file ?

@MickL
Copy link
Author

MickL commented Mar 1, 2017

typescript:

  1. npm install -g typescript
  2. tsc filename.ts (converts to js)

ts-node:

  1. npm install -g ts-node
  2. ts-node index.ts

@vmarchaud
Copy link
Contributor

We should be using ts-node (check here and here).
could you check that inside the node_modules of the pm2 installation (check it with which pm2), there is ts-node somewhere ?

@MickL
Copy link
Author

MickL commented Mar 1, 2017

Yes it is i checked everything alot of times. It has TypeScript dependency which has @types dependencies which seem not to be installed. Thats why it cant find node functions like require.

I opened an issue here:
microsoft/TypeScript#14390

@MickL
Copy link
Author

MickL commented Mar 1, 2017

I feel like npm is not installing ANY devDependencies. That would explain everything. Not sure if this is a global OS configuration or maybe new node 7 default. Can't find alot of informations tho.

Cumbersome workaround: Go into node_modules/typescript/ folder and do npm i -> Installs all devDependencies

@MickL
Copy link
Author

MickL commented Mar 1, 2017

If so pm2 should beneath typescript and ts-node install @types/node

@maxpaj
Copy link

maxpaj commented Sep 16, 2017

Any solution to this?

@coreylenertz
Copy link

Our team would like to minimize the number of steps needed to deploy a typescript application. Initially, we thought specifying the script would be enough. We've also tried using ts-node as the interpreter. We've found either approach does not work on Windows using version 2.7.1. It sounds like others are experiencing the same issues. Happy to provide additional details if needed.

Error: spawn C:\Users\...\AppData\Roaming\npm\node_modules\pm2\node_modules\.bin\ts-node ENOENT

@rahuljain1311
Copy link

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.

@wallet77
Copy link
Contributor

wallet77 commented Jul 9, 2018

Close this one cause duplicate of :#3312
Feel free to reopen if necessary.

@wallet77 wallet77 closed this as completed Jul 9, 2018
@captain-yossarian
Copy link

I have the same problem.
error_pm2

Text from log file:

App [index:0] online
2018-12-15T16:48:38: PM2 error: Error: spawn C:\Users\sbilyk\AppData\Roaming\npm\node_modules\pm2\node_modules.bin\ts-node ENOENT
at Process.ChildProcess._handle.onexit (internal/child_process.js:232:19)
at onErrorNT (internal/child_process.js:407:16)
at process._tickCallback (internal/process/next_tick.js:63:19)

PM2 works as expected with pure js projects, but does not work with typescript. I have tried to install globally and locally typescript and node-ts and other. It just does not work.
What I'm doing wrong?
@wallet77 Can you please reopen this issue?

@himself65
Copy link

pm2 install typescript && pm2 install ts-node

@captain-yossarian
Copy link

captain-yossarian commented Dec 31, 2018

@himself65 I've tried it

@himself65
Copy link

@SerhiiBilyk
you can see my repo
https://github.com/Himself65/Astoria

@captain-yossarian
Copy link

@himself65 thank you. I think problem exists because I'm using tsconfig-paths/register

  "scripts": {
    "start": "cross-env NODE_ENV=local ts-node -r tsconfig-paths/register index.ts",
    "start:dev": "cross-env NODE_ENV=dev ts-node -r tsconfig-paths/register index.ts",
    "start:prod": "cross-env NODE_ENV=prod ts-node index.ts",
    "test": "jest --detectOpenHandles controllers/",
    "prettier": "prettier --write **/*.ts"
  },

Still have next error:

[PM2] Spawning PM2 daemon with pm2_home=C:\Users\sbilyk.pm2
[PM2] PM2 Successfully daemonized
[PM2][Module] Starting NPM module ts-node
[PM2][WARN] Applications bin not running, starting...
[PM2] App [ts-node] launched (1 instances)
[PM2][Module] Starting NPM module node-ts
[PM2][WARN] Applications node-ts not running, starting...
[PM2] App [node-ts] launched (1 instances)
[PM2][ERROR] File ecosystem.config.js not found

@Halkeey
Copy link

Halkeey commented Feb 15, 2019

This works for me:
$ npm install typescript --ugv
$ npm install ts-node --ugv

@pixelsbysarah
Copy link

I've had no luck with any of the solutions mentioned above. Perhaps this newer issue is why we are seeing this issue again: #4142

@renjithspace
Copy link

It's very simple guys.

Just use tsc and pm2 watch combination with single & to run both commands.

"scripts": {
    "serve": "tsc src/app.ts -w & pm2 start dist/app.js --watch"
},

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests