Ts-node: Does not work after upgrading to 4.0.0

Created on 11 Dec 2017  路  16Comments  路  Source: TypeStrong/ts-node

ts-node just suddenly stop working after upgrading to 4.0.0 (The same with 4.0.1):

nodemon.json

{
    "watch": ["src"],
    "ext": "ts",
    "ignore": ["src/**/*.spec.ts"],
    "exec": "ts-node -P ./tsconfig.json --no-cache ./src/index.ts"
}

tsconfig.json

{
    "compilerOptions": {
        "target": "esnext",
        "module": "commonjs",
        "sourceMap": true,
        "lib": ["esnext"],
        "outDir": "build",
        "rootDir": "src",
        "importHelpers": true,
        "noEmitOnError": true,
        "strict": true,
        "noUnusedLocals": true,
        "noUnusedParameters": true,
        "noImplicitReturns": true,
        "noFallthroughCasesInSwitch": true,
        "moduleResolution": "node",
        "experimentalDecorators": true,
        "emitDecoratorMetadata": true
    }
}

nodemon: 1.12.5 (dev dependency)
typescirpt: 2.6.2 (dev dependency)
ts-node: 4.0.1 (dev dependency)

Reverted ts-node back to 3.30 solved the problem.

bug

Most helpful comment

node v8.9.0 Win8.1x64 node -r ts-node/register works for me.

All 16 comments

Hi, i have the same problem when using ts-node >= 4.x.x. When i save a file, node process isn't killed and both dev port and inspector port remains used. If i downgrade to 3.x.x, it starts working again. I use this npm scripts to start in dev mode:
"nodemon": "nodemon -e ts -w \"./src\" -x \"npm run debug\"",
"debug": "ts-node --inspect ./src/index.ts",

Possible duplicate #481

Can you share the OS or other information so someone can help debug?

macOS: 10.13.2
nodemon: 1.12.5 (dev dependency)
typescirpt: 2.6.2 (dev dependency)
ts-node: 4.0.1 (dev dependency)

I haven't spare time to debug at the moment , otherwise i could do it and post even more info.

Interesting, thanks. I thought it may have been a duplicate of https://github.com/TypeStrong/ts-node/issues/481, but not if it's on mac. Looks like these issues may be negative side effects of https://github.com/TypeStrong/ts-node/pull/419.

For anyone running into this, can you switch to using node -r ts-node/register? This avoids many of the process issues that were occurring and is likely the recommended way to use in the next release.

node v8.9.0 Win8.1x64 node -r ts-node/register works for me.

@blakeembrey just switched on my windows machine and everything seems to work fine when I rebuild from master on the repo. I do run into this issue when installing from NPM however.

@stelcheck That's really odd, there shouldn't be a difference between what's on master. Can you diff your built files at all? Maybe something in my release pipeline broke, that would be odd.

Never mind, I was able to reproduce the issue locally.

There seems to be two issues: one related to how early errors are piped through on Windows (maybe mac?), the other I am still investigating. Trying to get a PR in ASAP.

@blakeembrey Also not work after upgrade 4.0.1

OS: Win10
Node: 8.9.1

The cause of the issue appears to be that process.stdin/out/err cannot be inherited by spawned processes on Windows. I couldn't find a solid reference to that issue, but that's the only thing that seems to be different.

That explains both why nothing gets printed out (the error happens in the subprocess, and its stdout/err is not piped to the main process), but also explains the actual crash (stdin is not a TTY, and no file names are being passed, so the code tries to read... nothing)

Since the reason that happens on Windows is because of a fix that was made essentially for *nix system, I'd say the simplest solution would be to not run in detached mode on Windows. I'll make a PR for that right now.

Addendum: I suspect there might be something going on when using ts-node as a sub-process as well. (which would explain issues on macOS). I'll reboot on Linux soon and will check that as well.

Just double-checked on Linux:

echo "process.on('SIGINT', () => console.log('called')); setInterval(() => console.log('sadasd'), 1000)" | node dist/bin.js

This seems to work properly. @fox1t is it possible that you also catch 'SIGTERM' in your app? You might also want to look into configuring a specific signal for nodemon https://github.com/remy/nodemon/pull/725 89 (been a while I haven't used it, assuming this is still configurable).

@fox1t Also, I see this issue in nodemon's issue tracker: https://github.com/remy/nodemon/issues/1164 - the reporter is on Windows, but perhaps it is related to your issue as well?

Here is another PR which would also solve the issue by simply removing subprocesses overall: https://github.com/TypeStrong/ts-node/pull/499

Same problem here after upgrade from 3.3.0 to 4.0.2
Windows 10,
Node 9.2.0

However it works fine on CI (unix) build server.

Was this page helpful?
0 / 5 - 0 ratings