Coder Social home page Coder Social logo

ts-node-dev's Introduction

ts-node-dev

Tweaked version of node-dev that uses ts-node under the hood.

It restarts target node process when any of required files changes (as standard node-dev) but shares Typescript compilation process between restarts. This significantly increases speed of restarting comparing to node-dev -r ts-node/register ..., nodemon -x ts-node ... variations because there is no need to instantiate ts-node compilation each time.

Install

npm (scoped) Build Status

yarn add ts-node-dev --dev
npm i ts-node-dev --save-dev

Usage

ts-node-dev [node-dev|ts-node flags] [ts-node-dev flags] [node cli flags] [--] [script] [script arguments]

So you just combine node-dev and ts-node options (see docs of those packages):

ts-node-dev --respawn --transpile-only server.ts

There is also short alias tsnd for running ts-node-dev:

tsnd --respawn server.ts

Look up flags and options can be used in ts-node's docs.

Also there are additional options specific to ts-node-dev:

  • --ignore-watch - (default: []) - files/folders to be ignored by node-dev. But this behaviour is enhanced: it also supports regular expression in the ignore strings and will check absolute paths of required files for match.

  • --deps - Also watch node_modules; by default watching is turned off

  • --debug - Some additional [DEBUG] output

  • --quiet - Silent [INFO] messages

  • --interval - Polling interval (ms) - DOESN'T WORK CURRENTLY

  • --debounce - Debounce file change events (ms, non-polling mode)

  • --clear (--cls) - Will clear screen on restart

  • --watch - Explicitly add arbitrary files or folders to watch and restart on change (list separated by commas, chokidar patterns)

  • --exit-child - Adds 'SIGTERM' exit handler in a child process.

  • --rs - Allow to restart with "rs" line entered in stdio, disabled by default.

  • --notify - to display desktop-notifications (Notifications are only displayed if node-notifier is installed).

  • --cache-directory - tmp dir which is used to keep the compiled sources (by default os tmp directory is used)

If you need to detect that you are running with ts-node-dev, check if process.env.TS_NODE_DEV is set.

Points of notice:

  • If you want desktop-notifications you should install node-notifier package and use --notify flag.

  • Especially for large code bases always consider running with --transpile-only flag which is normal for dev workflow and will speed up things greatly. Note, that ts-node-dev will not put watch handlers on TS files that contain only types/interfaces (used only for type checking) - this is current limitation by design.

  • --ignore-watch will NOT affect files ignored by TS compilation. Use --ignore option (or TS_NODE_IGNORE env variable) to pass RegExp strings for filtering files that should not be compiled, by default /node_modules/ are ignored.

  • Unknown flags (node cli flags are considered to be so) are treated like string value flags by default. The right solution to avoid ambiguity is to separate script name from option flags with --, for example:

    ts-node-dev --inspect -- my-script.ts
    
  • The good thing is that ts-node-dev watches used tsconfig.json file, and will reinitialize compilation on its change, but you have to restart the process manually when you update used version of typescript or make any other changes that may effect compilation results.

Issues

If you have an issue, please create one. But, before:

  • try to check if there exits alike issues.
  • try to run your code with just ts-node
  • try to run your code with --files option enabled (see ts-node docs)
  • try to run it with --debug flag and see the output
  • try to make create repro example

Versioning

Currently versioning is not stable and it is still treated as pre-release. You might expect some options API changes. If you want to avoid unexpected problems it is recommended to fixate the installed version and update only in case of issues, you may consult CHANGELOG for updates.

License

MIT.

ts-node-dev's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ts-node-dev's Issues

ts-node-dev sometimes uses old versions of files for compilation

I am seeing ts-node-dev fail to hot reload files sometimes (even though it notices the file changes and tries to restart according to the output). I don't have any steps to repro and I'm seeing this randomly every 2-3 days.

It seems different enough from the other issues i've seen on here to make its own thread.

I will fully explain my workflow for the most recent case as it may shed some light.

the error looked like:

[INFO] 15:58:29 Restarting: /Users/ryan/app_engine/StoryDoodle/src/server/util/redis.ts has been modified
Using ts-node version 8.0.2, typescript version 3.3.3333
[ERROR] 15:58:32 ⨯ Unable to compile TypeScript:
src/server/cache/JSONCache.ts(5,34): error TS2551: Property 'getAsync' does not exist on type 'IPromisifedRedis'. Did you mean 'hmgetAsync'?
src/server/cache/JSONCache.ts(16,17): error TS2339: Property 'setAsync' does not exist on type 'IPromisifedRedis'.

This is a normal and explainable error but it was only possible with an old file of /util/redis.ts because that's the only time I had hmgetAsync type defined. In addition, other files which depend on this file are compiling correctly. (they should fail on that version of the file)

My flow:

  1. Make /util/redis.ts with version A (which would not have this error)
  2. Make another file that debends on and works with /util/redis.ts
  3. Modify /util/redis.ts to version B (which should produce this error)
  4. Change my mind and change /util/redis.ts back to version A
  5. Compilation is fine.
  6. Create a new file that depends on /util/redis.ts
  7. Get this error (which could only occur on version B of /util/redis.ts)
  8. Try to resolve error by editing files. This causes visible reloads but error still persists
  9. Restarting ts-node-dev by killing and re-running compiles properly

my command: ts-node-dev --respawn src/server/index.ts
OS: MAC OSX 10.14
ts-node-dev version: 1.0.0-pre.32

I can do additional debugging the next time this happens. Just let me know what might help.

TypeScript Slow Restarting Time

When I start app ts compile very fast, but when I change some file It take to long to restart, in which may be problem ?

./node_modules/.bin/tsc -project ./tsconfig.json --diagnostics

Files:           403
Lines:         64126
Nodes:        237079
Identifiers:   83972
Symbols:       67964
Types:          7966
Memory used: 112027K
I/O read:      0.04s
I/O write:     0.09s
Parse time:    0.89s
Bind time:     0.28s
Check time:    0.66s
Emit time:     0.45s
Total time:    2.28s

tsconfig.json

{
  "compilerOptions": {
    "target": "es6",
    "module": "commonjs",
    "lib": ["es6", "es2017"],
    "sourceMap": true,
    "outDir": "./dist",
    "moduleResolution": "node",

    "removeComments": true,
    "noImplicitAny": true,
    "strictNullChecks": true,
    "strictFunctionTypes": true,
    "noImplicitThis": true,
    "noUnusedLocals": true,
    "noUnusedParameters": true,
    "noImplicitReturns": true,
    "noFallthroughCasesInSwitch": true,
    "allowSyntheticDefaultImports": true,
    "skipLibCheck": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true
  },
  "exclude": ["node_modules"],
  "include": ["src"]
}

Super ugly stack trace

Hello,

I like ts-node-dev very much, but there's a problem that drives me mad.

When there's a typescript error in my code, here's what I see in console:
(This is how I use it: "start": "ts-node-dev --inspect --no-notify -r dotenv/config src/index.ts")

Compilation error: { TSError:  Unable to compile TypeScript
src\index.ts (14,7): Argument of type '5' is not assignable to parameter of type 'string'. (2345)
    at getOutput (C:\Projects\graphql-server-example\node_modules\ts-node-dev\node_modules\ts-node\src\index.ts:330:15)
    at Object.compile (C:\Projects\graphql-server-example\node_modules\ts-node-dev\node_modules\ts-node\src\index.ts:516:11)
    at Object.m._compile (C:\Projects\graphql-server-example\node_modules\ts-node-dev\node_modules\ts-node\src\index.ts:403:43)
    at Object.compile (C:\Projects\graphql-server-example\node_modules\ts-node-dev\lib\compiler.js:156:9)
    at ChildProcess.<anonymous> (C:\Projects\graphql-server-example\node_modules\ts-node-dev\lib\index.js:103:16)
    at ChildProcess.emit (events.js:187:15)
    at emit (internal/child_process.js:807:12)
    at process._tickCallback (internal/process/next_tick.js:63:19)
  diagnostics:
   [ { message: 'src\\index.ts (14,7): Argument of type \'5\' is not assignable to parameter of type \'string\'. (2345)',
       code: 2345 } ] }
Error: Unable to compile TypeScript
    at Object.<anonymous> (C:\Projects\graphql-server-example\src\index.ts:1:69)
    at Module._compile (internal/modules/cjs/loader.js:678:30)
    at Module.m._compile (C:\Users\congy\AppData\Local\Temp\ts-node-dev-hook-7084678494623908.js:44:25)
    at Module._extensions..js (internal/modules/cjs/loader.js:689:10)
    at require.extensions.(anonymous function) (C:\Users\congy\AppData\Local\Temp\ts-node-dev-hook-7084678494623908.js:46:14)
    at Object.nodeDevHook [as .ts] (C:\Projects\graphql-server-example\node_modules\ts-node-dev\lib\hook.js:61:7)
    at Module.load (internal/modules/cjs/loader.js:589:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:528:12)
    at Function.Module._load (internal/modules/cjs/loader.js:520:3)
    at Module.require (internal/modules/cjs/loader.js:626:17)
[ERROR] 14:38:38 Error: Unable to compile TypeScript

Here's what I actually want to see:

[ERROR] 14:38:38: TSError:  Unable to compile TypeScript
src\index.ts (14,7): Argument of type '5' is not assignable to parameter of type 'string'.

I have the latest version of typescript, node, ts-node and ts-node-dev.

Is there a way to improve these stacktraces? Or am I doing something wrong?

Thanks

Hot reload breaks with webpack

If the script runs webpack build, ts-node-dev's reload stops working. It detects that a module has changed, but doesn't really restart the app.

Steps to reproduce

In empty directory, run yarn add nuxt ts-node-dev typescript, create test.ts:

import { Nuxt, Builder } from 'nuxt'

console.log('Loading...')

const nuxt = new Nuxt({ dev: false })
nuxt.listen(3000)

const builder = new Builder(nuxt)
// builder.build() // <--- Uncommenting this line breaks ts-node-dev's reload.

console.log(`Listening since ${new Date()}.`)

then run: npx ts-node-dev test

Actual behaviour

ts-node-dev will restart the server when the file is modified. However, once builder.build() is uncommented, it will no more react on file changes.

Example output:

❯ npx ts-node-dev test
Loading...
Listening since Thu Oct 04 2018 14:48:44 GMT+0700 (Novosibirsk Standard Time).
[INFO] 14:48:55 Restarting: /Users/semenov/tmp/ts2/test.ts has been modified
Loading...
L1istening since Thu Oct 04 2018 14:48:57 GMT+0700 (Novosibirsk Standard Time).
[INFO] 14:49:01 Restarting: /Users/semenov/tmp/ts2/test.ts has been modified
Loading...
Listening since Thu Oct 04 2018 14:49:03 GMT+0700 (Novosibirsk Standard Time).
[INFO] 14:49:09 Restarting: /Users/semenov/tmp/ts2/test.ts has been modified
Loading...


 INFO  Building project

Listening since Thu Oct 04 2018 14:49:11 GMT+0700 (Novosibirsk Standard Time).
✔ success Builder initialized
✔ success Nuxt files generated


 READY  Listening on http://:::3000

[INFO] 14:49:40 Restarting: /Users/semenov/tmp/ts2/test.ts has been modified

^^^ after that it's stuck.

Expected

ts-node-dev continues to reload if test.ts is modified.


The same problem happens not only with Nuxt but with Ream, so I believe it's caused by webpack4 which is used by both. I think it is not caused by webpack's Hot Module Reload as it repeats even with { dev: false } which I believe disables HMR (but I'm not 100% sure in that).

Can support monitor yarn link module modifications?

ts-node-dev is an Amazing project, Thanks.

I has a project grouped with two local TypeScript sub-projects.
(1) my-utils
(2) my-backend (a Koa project)

Before development in a new PC, I will:
in my-utils folder execute yarn link
in my-backend folder execute yarn link my-utils

So when I modified source files of my-utils, I do not need to "publish my-utils to some repo server and then yarn add or yarn update in my-backend", the modifications of my-utils can be used by my-backend directly.

With ts-node-dev, How can respawn my-backend service when I modified some source files of my-utils?
Thanks for your reply :)

Legacy watch mode

Hi @whitecolor,

I really love your project, it's awesome.

But I am running into a problem setting up ts-node-dev within a Docker container, which is using a mounted driver. In Nodemon documentation, they are having Legacy Watch mode that works very well in this case.

It would be nice if we also have something like this.
🚀

Can tsconfig.json be made optional?

I've just started a new Node.js project – all it has is src/index.ts and ts-node / typescript as dev dependencies. Despite that there is no tsconfig.json, the following dev command works properly (I assume that some defaults are picked):

  "scripts": {
    "dev": "ts-node src/index.ts"
  },

After yarn add --dev [email protected] and replacing ts-node src/index.ts with ts-node-dev --respawn --notify=false src/index.ts, I'm seeing the following error:

/private/var/folders/kz/lrtmrvld16q_q45z8pg1dsskrbyg3_l/T/ts-node-dev-hook-42574828773943385.js:99
      throw new Error('Waiting ts-node-dev ready file failed')
      ^

Error: Waiting ts-node-dev ready file failed
    at Object.<anonymous> (/private/var/folders/kz/lrtmrvld16q_q45z8pg1dsskrbyg3_l/T/ts-node-dev-hook-42574828773943385.js:99:13)
    at Module._compile (internal/modules/cjs/loader.js:689:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
    at Module.load (internal/modules/cjs/loader.js:599:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
    at Function.Module._load (internal/modules/cjs/loader.js:530:3)
    at Module.require (internal/modules/cjs/loader.js:637:17)
    at Module._preloadModules (internal/modules/cjs/loader.js:805:12)
    at preloadModules (internal/bootstrap/node.js:588:7)
    at startup (internal/bootstrap/node.js:269:9)

Creating tsconfig.json with an empty object resolves the issue. However, given that in my case this new file does not carry any payload and ts-node works without it, can it be made optional for ts-node-dev as well?

Allow post params in command line

Yet this is possible :

"scripts": {
  "start": "ts-node-dev src/main/index.ts",
  "watch": "ts-node-dev --respawn src/main/index.ts",
}

This is not :

"scripts": {
  "start": "ts-node-dev src/main/index.ts",
  "watch": "yarn start -- --respawn",
// or with modern npm
  "watch": "yarn start --respawn"
}

Should be great to allow :
ts-node-dev src/main/index.ts --respawn
To fix this issue

execArgv handled inconsistently with ts-node

$ cat 1.ts
console.log(process.execArgv)
$ npx ts-node -r dotenv/config -r tsconfig-paths/register 1.ts
[ '/Users/semenov/xxx/node_modules/ts-node/dist/bin.js' ]
$ npx ts-node-dev -r dotenv/config -r tsconfig-paths/register 1.ts
[ '-r',
  '/var/folders/vt/zzlb2fld1g1078d9t5l03ytc0000gn/T/ts-node-dev-hook-47635269794487.js',
  '-r',
  'dotenv/config',
  '-r',
  'tsconfig-paths/register' ]
$ npx ts-node --version
ts-node v7.0.0
node v10.4.1
typescript v2.9.2
cache "/var/folders/vt/zzlb2fld1g1078d9t5l03ytc0000gn/T/ts-node-b0380aaf696a550107706dcea5e8fbebdafc39ed1e55aff7ad273f84ddc78e31/db61f91ee3ce8b8eee63de957f0d611915f702da0a679c2e973cdb7e332b20fb"
$ grep ts-node-dev package.json
    "ts-node-dev": "^1.0.0-pre.26",

This makes it hard to create reusable code that relies on execArgv (e.g. for further multi-processing with fork()).

Any chance for this to be fixed (I guess not), or is there a suggested workaround?

My context is that I want to fork a Typescript module with tsconfig-paths continuing to work, and it currently requires two different versions of code for ts-node and ts-node-dev:

// ts-node only
// if called in ts-node-dev, leads to Error: Cannot find module '-r'
fork(path.resolve(__dirname, 'worker'), [], {
  execArgv: [ process.execArgv[0], '-r', 'tsconfig-paths/register' ]
})

// ts-node-dev only
// if called in ts-node, leads to errors during imports using tsconfig paths aliases
fork(path.resolve(__dirname, 'worker'))

when I run my ts project with unmerged git conflicts I also get this error: Cannot find module '/tmp/ts-node-dev-hook-5528925656195942.js'

NODE_ENV=development LOOOP_ENVIRONMENT=dev DEBUG=looop*,knex:query,knex:bindings ts-node-dev --transpileOnly src/server.js

tsconfig.json(17,1): error TS1185: Merge conflict marker encountered.

module.js:549
    throw err;
    ^

Error: Cannot find module '/tmp/ts-node-dev-hook-5528925656195942.js'
    at Function.Module._resolveFilename (module.js:547:15)
    at Function.Module._load (module.js:474:25)
    at Module.require (module.js:596:17)
    at Function.Module._preloadModules (module.js:753:12)
    at preloadModules (bootstrap_node.js:472:38)
    at startup (bootstrap_node.js:185:9)
    at bootstrap_node.js:609:3

would be nice if ts-node-dev could handle this edgecase gracefully

Error: Cannot find module 'mkdirp'

Hi first time using your module.

I'm using :
ts-node-dev: 1.0.0-pre.7
npm: 5.6.0
node: 8.9.4
on windows 10

When trying to use it with :

ts-node-dev

or

ts-node-dev --respawn *.ts

through the command line i'm runnning into this error :

Error: Cannot find module 'mkdirp'

Can you help me ? Thanks.

unique tmpDir not removed

the unique tmpDir created with fs.mkdtempSync('.ts-node') is not removed on subsequent inits, leaving the root dir cluttered with empty .ts-nodeXYZ folders

Error: Could not require <path>/node_modules/koa/lib/response.js

Hi,
I habe a Koa based Typescript application and when I try to run it, I get this error:

$ ts-node-dev src/server/server.ts
Error: Could not require /Users/<path>/node_modules/koa/lib/response.js, compiled path:/var/folders/bd/9xvc6tls6t59tfrxn_vm22m80000gp/T/.ts-node/compiled/node_modules_koa_lib_response_js_ec7c7147dccedf853a26eeb31b46f4250fa2f99a9774232bc686fb937e034307.js
    at compile (/private/var/folders/bd/9xvc6tls6t59tfrxn_vm22m80000gp/T/ts-node-dev-hook-1508310397187.js:26:13)
    at Module.m._compile (/private/var/folders/bd/9xvc6tls6t59tfrxn_vm22m80000gp/T/ts-node-dev-hook-1508310397187.js:70:38)
    at Module._extensions..js (module.js:635:10)
    at require.extensions..js (/private/var/folders/bd/9xvc6tls6t59tfrxn_vm22m80000gp/T/ts-node-dev-hook-1508310397187.js:73:14)
    at Object.nodeDevHook [as .js] (/Users/<path>/.nvm/versions/node/v8.7.0/lib/node_modules/ts-node-dev/lib/hook.js:61:7)
    at Module.load (module.js:545:32)
    at tryModuleLoad (module.js:508:12)
    at Function.Module._load (module.js:500:3)
    at Module.require (module.js:568:17)
    at require (internal/module.js:11:18)
[ERROR] 09:06:48 Error

No support for node --eval flag

Hi, before getting into the issue, I would like to thank you for this package, as it is zero configuration. And I love zero config packages, especially in the JS ecosystem.

Now I have a problem with ts-node-dev to evaluate scripts from the CLI, with the --eval node flag.

"scripts": {
  "start": "ts-node --eval \"console.log('Hello')\"",
  "dev-a": "ts-node-dev --eval \"console.log('Hello')\"",
  "dev-b": "ts-node-dev --eval -- \"console.log('Hello')\"",
}
  • Script start with just ts-node works fine, prints Hello.

  • Script dev-a prints Usage: ts-node-dev [options] script [arguments], as it should be, given the readme section about node flags.

  • Script dev-b prints an error Error: Cannot find module 'console.log('Hello')' since it probably evaluates the argument as a path to a module.

Feature Request Lazy Time

It would be nice to have a lazy reaction time of restarting configurable.

The idea is that the there need to be no change in that time in order to restart.
When changing multiple files projects it keeps always restarting eating up cpu power.

So i could conifgure for example 30sec means: No change since 30 sec than restart

ts-node -O (--compilerOptions) failing

Hi,

I have been playing with ts-node-dev with a project using ES2016 modules. To get round my TypeScript output ES2016 modules not working in node I have been trying to run ts-node-dev in my package.json as follows

ts-node-dev -O '{\ "module\": \"commonjs\" }' --respawn ./src/index.ts

I am getting the following error:

{ TSError: ⨯ Unable to compile TypeScript
Unknown compiler option '0'. (5023)
Unknown compiler option '1'. (5023)
Unknown compiler option '2'. (5023)
Unknown compiler option '3'. (5023)
Unknown compiler option '4'. (5023)
Unknown compiler option '5'. (5023)
Unknown compiler option '6'. (5023)
Unknown compiler option '7'. (5023)
Unknown compiler option '8'. (5023)
Unknown compiler option '9'. (5023)
Unknown compiler option '10'. (5023)
Unknown compiler option '11'. (5023)
Unknown compiler option '12'. (5023)
Unknown compiler option '13'. (5023)
Unknown compiler option '14'. (5023)
Unknown compiler option '15'. (5023)
Unknown compiler option '16'. (5023)
Unknown compiler option '17'. (5023)
Unknown compiler option '18'. (5023)
Unknown compiler option '19'. (5023)
Unknown compiler option '20'. (5023)
Unknown compiler option '21'. (5023)
Unknown compiler option '22'. (5023)
Unknown compiler option '23'. (5023)
    at register (/Users/markfknight/Documents/Projects/vue-rx-property-decorator/node_modules/ts-node/src/index.ts:220:11)
    at Object.init (/Users/markfknight/Documents/Projects/vue-rx-property-decorator/node_modules/ts-node-dev/lib/compiler.js:97:7)
    at module.exports (/Users/markfknight/Documents/Projects/vue-rx-property-decorator/node_modules/ts-node-dev/lib/index.js:9:12)
    at Object.<anonymous> (/Users/markfknight/Documents/Projects/vue-rx-property-decorator/node_modules/ts-node-dev/bin/ts-node-dev:60:1)
    at Module._compile (module.js:662:30)
    at Object.Module._extensions..js (module.js:673:10)
    at Module.load (module.js:575:32)
    at tryModuleLoad (module.js:515:12)
    at Function.Module._load (module.js:507:3)
    at Function.Module.runMain (module.js:703:10)
  diagnostics:
   [ { message: 'Unknown compiler option \'0\'. (5023)', code: 5023 },
     { message: 'Unknown compiler option \'1\'. (5023)', code: 5023 },
     { message: 'Unknown compiler option \'2\'. (5023)', code: 5023 },
     { message: 'Unknown compiler option \'3\'. (5023)', code: 5023 },
     { message: 'Unknown compiler option \'4\'. (5023)', code: 5023 },
     { message: 'Unknown compiler option \'5\'. (5023)', code: 5023 },
     { message: 'Unknown compiler option \'6\'. (5023)', code: 5023 },
     { message: 'Unknown compiler option \'7\'. (5023)', code: 5023 },
     { message: 'Unknown compiler option \'8\'. (5023)', code: 5023 },
     { message: 'Unknown compiler option \'9\'. (5023)', code: 5023 },
     { message: 'Unknown compiler option \'10\'. (5023)',
       code: 5023 },
     { message: 'Unknown compiler option \'11\'. (5023)',
       code: 5023 },
     { message: 'Unknown compiler option \'12\'. (5023)',
       code: 5023 },
     { message: 'Unknown compiler option \'13\'. (5023)',
       code: 5023 },
     { message: 'Unknown compiler option \'14\'. (5023)',
       code: 5023 },
     { message: 'Unknown compiler option \'15\'. (5023)',
       code: 5023 },
     { message: 'Unknown compiler option \'16\'. (5023)',
       code: 5023 },
     { message: 'Unknown compiler option \'17\'. (5023)',
       code: 5023 },
     { message: 'Unknown compiler option \'18\'. (5023)',
       code: 5023 },
     { message: 'Unknown compiler option \'19\'. (5023)',
       code: 5023 },
     { message: 'Unknown compiler option \'20\'. (5023)',
       code: 5023 },
     { message: 'Unknown compiler option \'21\'. (5023)',
       code: 5023 },
     { message: 'Unknown compiler option \'22\'. (5023)',
       code: 5023 },
     { message: 'Unknown compiler option \'23\'. (5023)',
       code: 5023 } ] }
module.js:559
    throw err;
    ^

Error: Cannot find module '/var/folders/xf/j5rpxz_51lzc5bz8trk2194r0000gn/T/ts-node-dev-hook-1520191060655.js'
    at Function.Module._resolveFilename (module.js:557:15)
    at Function.Module._load (module.js:484:25)
    at Module.require (module.js:606:17)
    at Function.Module._preloadModules (module.js:763:12)
    at preloadModules (bootstrap_node.js:526:38)
    at startup (bootstrap_node.js:190:9)
    at bootstrap_node.js:660:3

Hitting ts-node directly with the -O flag does not through the error.

OSX: 10.13.3
Node: v9.7.1
TypeScript: 2.7.2
ts-node-dev: 1.0.0-pre.17

Spaces in project path will break ts-node-dev

When running ts-node-dev in a project which contains spaces in its directory path, it will simply crash. The error message is along the lines of Error: Cannot find module 'C:\Users\USER\All' where the path should b e C:\Users\USER\All Projects\.... Maybe this is just Windows-related.

TS_NODE_IGNORE is not passed

Hello,

I just tried to change nodemon for ts-node-dev but it's not working for me.
I get this error: SyntaxError: Unexpected token import

My guess is that it's coming from lodash-es. I used to solve this issue by adding the env variable TS_NODE_IGNORE= '/node_modules/(?!lodash-es/.*)' it's working with nodemon but not ts-node-dev

I also tried:

ts-node-dev -F --ignore '/node_modules/(?!lodash-es/.*)' ./src/server/index.ts

(same result)

Feature request: cleanup and relaunch

Hi there, thanks for maintaining this awesome tool. It's a great way to reduce recompile times.

I'm trying to do something a little out of the ordinary. I'd like to have my dev server and my tests share the same in-memory ts-node compiler so I can quickly switch between running tests and playing with my dev server while making changes to my source files.

I'd also like to reuse ts-node-dev because you've already solved the main problem of hooking into require for transpilation and file watching. I believe I can achieve this by making it possible for ts-node-dev clean up after itself via a programmatic API.

What I mean is this:

const start = require("ts-node-dev/lib/index.js")
let dispose = start("my-server.ts");
...
dispose(); // filewatcher and child process get killed, but ts-node compiler sticks around
dispose = start("my-tests.ts"); // second `start()` call doesn't re-init compiler
...
dispose(); 

What do you think? If you're okay with this functionality, I can open a PR. Thanks!

Source maps don't seem to refresh immediately?

First off - mad props for this lib! It's the only means I've come across for implementing proper debugging with TS on the server side, owing to the fact that it's all a single process, which makes it possible to reload files without losing the debugging session.

I have run into a small problem, though - when I'm debugging my app in VS Code and I set a breakpoint, the breakpoint won't work anymore if the file is reloaded. Hovering over gives this message:

Unverified breakpoint, Breakpoint ignored because generated code not found (source map problem?).

If I disable and re-enable the breakpoint, it works again. Any idea what might be going on here? I would understand fully if you this is something out of your control, but I wanted to ask nonetheless to see if I missed something obvious. I recall hearing that the --nolazy flag is used to fix this with normal node, so maybe this is related?

This is my debugging launch config:

    {
      "type": "node",
      "request": "launch",
      "name": "ts node dev",
      "runtimeExecutable": "ts-node-dev",
      "args": ["--respawn", "--type-check", "src/index.ts"],
      "envFile": "${workspaceFolder}/.env",
      "restart": true,
      "console": "integratedTerminal",
      "internalConsoleOptions": "neverOpen",
      "sourceMaps": true
    }

Infinite 'uncaughtException' loop

Sometimes when my app crashes, it gets into an infinite loop of uncaught exceptions.

Stack trace:

Error [ERR_IPC_CHANNEL_CLOSED]: Channel closed
    at process.target.send (internal/child_process.js:613:16)
    at Object.exports.send (/opt/app/node_modules/ts-node-dev/lib/ipc.js:14:23)
    at process.<anonymous> (/opt/app/node_modules/ts-node-dev/lib/wrap.js:45:7)
    at process.emit (events.js:187:15)
    at process.emit (/opt/app/node_modules/source-map-support/source-map-support.js:454:21)
    at process._fatalException (internal/bootstrap/node.js:435:27)

Thank you!

This is awesome :-)

Keep up the good work! 👍

--preserve-symlinks isn't supported

Needing to use this to get symlinks/peerDeps working with a local dependency.
This works: node -r ts-node/register --preserve-symlinks src
But even if I add the whitelist to ts-node-dev, this doesn't work: ts-node-dev --preserve-symlinks src

This works: NODE_PRESERVE_SYMLINKS=1 ts-node-dev src

How to recompile on change of an import

I use yarn ts-node-dev --respawn --transpileOnly index.ts

My index.ts has 'import { MyClass} from './MyFile' #MyFile.ts & .js
I was able to trick ts-node-dev to notice changes to MyFile.ts with
require('./MyFile.ts')
BUT
ts-node-dev doesn't seem to make index.ts/js LOAD the updated MyFile.js.
Any suggestions?

Try to debug typescript file

HI Dev,
I try to debug typescript files, in visual studio code.
to run the code I using yarn ts-node-dev server.

Need help :)

configuration:
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "attach",
"name": "Attach by Process ID",
"processId": "${command:PickProcess}",
"port": 5858,
"outFiles": []
},
{
"type": "node",
"request": "launch",
"name": "Launch Program",
"program": "${workspaceFolder}/server.ts",
"preLaunchTask": "tsc: build - tsconfig.json",
"outFiles": [
"${workspaceFolder}/dist/**/*.js"
],
"cwd": "${workspaceRoot}"
}
]
}

error:
Cannot connect to runtime; make sure that runtime is in 'legacy' debug mode.

Running ts-node-dev at two projects at the same time crashes

After launching the second time ts-node-dev, the first one throws this error:

/home/user/.local/lib/node_modules/ts-node-dev/lib/index.js:81
        var split = data.split('\n')
                         ^
TypeError: Cannot read property 'split' of undefined
    at ReadFileContext.callback (/home/user/.local/lib/node_modules/ts-node-dev/lib/index.js:81:26)
    at FSReqWrap.readFileAfterOpen [as oncomplete] (fs.js:420:13)

TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be one of type string, Buffer, or URL. Received type undefined

ts-node-dev v1.0.0-pre.28 does not compile my project with the following message:

TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be one of type string, Buffer, or URL. Received type undefined
    at Object.fs.openSync (fs.js:572:3)
    at Object.fs.readFileSync (fs.js:485:33)
    at Object.compile (/Users/gfx/.ghq/github.com/bitjourney/kibela/node_modules/ts-node-dev/lib/compiler.js:145:19)
    at ChildProcess.<anonymous> (/Users/gfx/.ghq/github.com/bitjourney/kibela/node_modules/ts-node-dev/lib/index.js:105:16)
    at ChildProcess.emit (events.js:187:15)
    at emit (internal/child_process.js:811:12)
    at process._tickCallback (internal/process/next_tick.js:63:19)

This is caused by fs.readFileSync and it's here:

https://github.com/whitecolor/ts-node-dev/blob/4dc3e17c369f580bd6be9e8c465ee95b8edc9432/lib/compiler.js#L142-L145

I have injected console.log("compile prams:", params) and it shows compile params: { ready: true }.

ts-node-dev runs on invalid tsconfig.json

If you have an invalid json configuration (but valid js object) ts-node-dev will run with no error:
i.e. (tsconfig.json):

{
  (...)
  "include": [
    "src/**/*.ts",
    "test/**/*.ts",
  ]
}

(the last comma in the include array makes the json config invalid)
This behavior is not all bad, but since tsconfig.json should be always a valid json and I'd expect the same behavior asts-node I think this is a that could be fixed.

Cryptic errors when running ts-node-dev

Hi @whitecolor!

I was trying to use ts-node-dev develop ts actions in my project, which are just runnable typescript files.

Here's what sometimes happens when I run yarn ts-node-dev --respawn --compile-timeout 30000 --notify=false src/actions/hello.ts:

yarn run v1.3.2
$ /path/to/project/node_modules/.bin/ts-node-dev --respawn --compile-timeout 30000 --notify=false src/actions/hello.ts
Error: Could not require /path/to/project/src/actions/hello.ts, compiled path:/var/folders/vp/cg66j_sj5_ncxlgvgt7pjn2h0000gn/T/.ts-node/compiled/src_actions_hello_ts_4b7034ed73736302bd98ace10b2ead962243eb48412af14fccc6e4c9447a0ee8.js
    at compile (/private/var/folders/vp/cg66j_sj5_ncxlgvgt7pjn2h0000gn/T/ts-node-dev-hook-1518358259402.js:27:13)
    at Module.m._compile (/private/var/folders/vp/cg66j_sj5_ncxlgvgt7pjn2h0000gn/T/ts-node-dev-hook-1518358259402.js:41:36)
    at Module._extensions..js (module.js:671:10)
    at require.extensions.(anonymous function) (/private/var/folders/vp/cg66j_sj5_ncxlgvgt7pjn2h0000gn/T/ts-node-dev-hook-1518358259402.js:43:14)
    at Object.nodeDevHook [as .ts] (/path/to/project/node_modules/ts-node-dev/lib/hook.js:61:7)
    at Module.load (module.js:573:32)
    at tryModuleLoad (module.js:513:12)
    at Function.Module._load (module.js:505:3)
    at Module.require (module.js:604:17)
    at require (internal/module.js:11:18)
[ERROR] 14:11:29 Error: Could not require /path/to/project/src/actions/hello.ts, compiled path:/var/folders/vp/cg66j_sj5_ncxlgvgt7pjn2h0000gn/T/.ts-node/compiled/src_actions_hello_ts_4b7034ed73736302bd98ace10b2ead962243eb48412af14fccc6e4c9447a0ee8.js
[INFO] 14:11:42 Restarting: /path/to/project/src/actions/hello.ts has been modified
Error: Could not require /path/to/project/src/lib/custom-sort-keys.ts, compiled path:/var/folders/vp/cg66j_sj5_ncxlgvgt7pjn2h0000gn/T/.ts-node/compiled/src_lib_custom_sort_keys_ts_85f47a355a422b5df586503ceb1aa07cc0328a953a0c9ebe77023bef5edbbdea.js
    at compile (/private/var/folders/vp/cg66j_sj5_ncxlgvgt7pjn2h0000gn/T/ts-node-dev-hook-1518358259402.js:27:13)
    at Module.m._compile (/private/var/folders/vp/cg66j_sj5_ncxlgvgt7pjn2h0000gn/T/ts-node-dev-hook-1518358259402.js:41:36)
    at Module._extensions..js (module.js:671:10)
    at require.extensions.(anonymous function) (/private/var/folders/vp/cg66j_sj5_ncxlgvgt7pjn2h0000gn/T/ts-node-dev-hook-1518358259402.js:43:14)
    at Object.nodeDevHook [as .ts] (/path/to/project/node_modules/ts-node-dev/lib/hook.js:61:7)
    at Module.load (module.js:573:32)
    at tryModuleLoad (module.js:513:12)
    at Function.Module._load (module.js:505:3)
    at Module.require (module.js:604:17)
    at require (internal/module.js:11:18)
[ERROR] 14:12:12 Error: Could not require /path/to/project/src/lib/custom-sort-keys.ts, compiled path:/var/folders/vp/cg66j_sj5_ncxlgvgt7pjn2h0000gn/T/.ts-node/compiled/src_lib_custom_sort_keys_ts_85f47a355a422b5df586503ceb1aa07cc0328a953a0c9ebe77023bef5edbbdea.js
[INFO] 14:12:16 Restarting: /path/to/project/src/actions/hello.ts has been modified
[INFO] 14:12:46 Restarting: /path/to/project/src/actions/hello.ts has been modified
Error: Could not require /path/to/project/src/lib/extract-legacy-assets-tree.ts, compiled path:/var/folders/vp/cg66j_sj5_ncxlgvgt7pjn2h0000gn/T/.ts-node/compiled/src_lib_extract_legacy_assets_tree_ts_1e7f51aadf447bb3e20188e0469ac27af6675f4ba2b32e9438614f59b57bc1c5.js
    at compile (/private/var/folders/vp/cg66j_sj5_ncxlgvgt7pjn2h0000gn/T/ts-node-dev-hook-1518358259402.js:27:13)
    at Module.m._compile (/private/var/folders/vp/cg66j_sj5_ncxlgvgt7pjn2h0000gn/T/ts-node-dev-hook-1518358259402.js:41:36)
    at Module._extensions..js (module.js:671:10)
    at require.extensions.(anonymous function) (/private/var/folders/vp/cg66j_sj5_ncxlgvgt7pjn2h0000gn/T/ts-node-dev-hook-1518358259402.js:43:14)
    at Object.nodeDevHook [as .ts] (/path/to/project/node_modules/ts-node-dev/lib/hook.js:61:7)
    at Module.load (module.js:573:32)
    at tryModuleLoad (module.js:513:12)
    at Function.Module._load (module.js:505:3)
    at Module.require (module.js:604:17)
    at require (internal/module.js:11:18)
Error [ERR_IPC_DISCONNECTED]: IPC channel is already disconnected
    at ChildProcess.target.disconnect (internal/child_process.js:746:26)
    at Pipe.channel.onread (internal/child_process.js:508:14)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

I don't understand where these are coming from and what is also strange is that I cannot make these errors reproducible for any specific content of my typescript files. For example, the error may show up at first, but then after I comment and uncomment a few lines, it disappears. At the same time, there is a likelihood that the process may completely crash, like in the example above.

Similar errors are shown when I run ts-node-dev without any options:

yarn ts-node-dev src/actions/hello.ts
yarn run v1.3.2
$ /path/to/project/node_modules/.bin/ts-node-dev src/actions/hello.ts
Error: Could not require /path/to/project/src/actions/hello.ts, compiled path:/var/folders/vp/cg66j_sj5_ncxlgvgt7pjn2h0000gn/T/.ts-node/compiled/src_actions_hello_ts_7ac73806ede5e6231c25cb24297c4973531ff760794d55c116c7d946dc8640a4.js
    at compile (/private/var/folders/vp/cg66j_sj5_ncxlgvgt7pjn2h0000gn/T/ts-node-dev-hook-1518358523172.js:27:13)
    at Module.m._compile (/private/var/folders/vp/cg66j_sj5_ncxlgvgt7pjn2h0000gn/T/ts-node-dev-hook-1518358523172.js:41:36)
    at Module._extensions..js (module.js:671:10)
    at require.extensions.(anonymous function) (/private/var/folders/vp/cg66j_sj5_ncxlgvgt7pjn2h0000gn/T/ts-node-dev-hook-1518358523172.js:43:14)
    at Object.nodeDevHook [as .ts] (/path/to/project/node_modules/ts-node-dev/lib/hook.js:61:7)
    at Module.load (module.js:573:32)
    at tryModuleLoad (module.js:513:12)
    at Function.Module._load (module.js:505:3)
    at Module.require (module.js:604:17)
    at require (internal/module.js:11:18)
[ERROR] 14:15:33 Error: Could not require /path/to/project/src/actions/hello.ts, compiled path:/var/folders/vp/cg66j_sj5_ncxlgvgt7pjn2h0000gn/T/.ts-node/compiled/src_actions_hello_ts_7ac73806ede5e6231c25cb24297c4973531ff760794d55c116c7d946dc8640a4.js

Despite all the errors above, running yarn ts-node src/actions/hello.ts works:

yarn run v1.3.2
$ /path/to/project/node_modules/.bin/ts-node src/actions/hello.ts
ACTION OUTPUT
✨  Done in 0.97s.

What could be causing this? How can I help with debugging given that I'm unable to craft a MWE?

My env:

node 9.5.0
yarn: 1.3.2
ts-node: 4.1.0
ts-node-dev 1.0.0-pre.9
macOS High Sierra

Difference between "node-dev -r ts-node/register"?

It seems I can accomplish the same feature by running node-dev with ts-node reigstered but does this package provide the same feature by a single command instead of providing ts-node as an argument? (Except for the new 3 launch parameters added.)

temp directory collision

Hi,

I am trying to compile 10 microservices at the same time. In fact, I configured webstorm to launch a ts-node-dev process for each microservice in a compound launch config. When I start this compound config, it starts the 10 processes at the same time. I see the following compilation error on the console of multiple processes:

Error reading compile request file { Error: ENOENT: no such file or directory, open '/var/folders/z4/g3h_kjf11zg0vbx1zdg6cn8c0000gn/T/.ts-node/compiled/8532484726430738.req'
  errno: -2,
  code: 'ENOENT',
  syscall: 'open',
  path: '/var/folders/z4/g3h_kjf11zg0vbx1zdg6cn8c0000gn/T/.ts-node/compiled/8532484726430738.req' }
Note that the path /var/folders/z4/g3h_kjf11zg0vbx1zdg6cn8c0000gn/T/.ts-node/compiled/... is the same for all of them. It really seems like all processes are trying to use the same temp directory.

Any idea is welcome!

Thanks!
Tamas

EMFILE: too many open files, watch

My server crashes when I tried replacing nodemon with this package.

Error: EMFILE: too many open files, watch
    at FSEvent.FSWatcher._handle.onchange (internal/fs/watchers.js:123:28)
Error: Unexpected exit status for 'node_modules/.bin/ts-node-dev  --project tsconfig.server.json src/tools/runServer.ts --fast --minifiy --offline --verbose': got 1, expected 0
    at ChildProcess.<anonymous> (/Users/chet/Code/notion-next/src/cli/utils.ts:334:6)
    at ChildProcess.emit (events.js:197:13)
    at ChildProcess.EventEmitter.emit (domain.js:446:20)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:254:12)

Stack trace shows wrong line number

It looks like stack traces don't report the correct line number.
Reproduction steps:

  • Create a file index.ts as:
/**
 * Some
 * long
 * comments
 * to offset sources
 */


 
throw new Error();
  • With stock typescript config (no tsconfig.json), run ts-node-dev index.ts
  • The output is:
Using ts-node version 7.0.1, typescript version 3.2.2
Error
    at Object.<anonymous> (/Users/gael/dev/index.ts:7:7)
    at Module._compile (internal/modules/cjs/loader.js:654:30)
    at Module.m._compile (/private/var/folders/_9/37c42sdn1c31kmk9mcp0z9qc0000gn/T/ts-node-dev-hook-9368575770193885.js:55:25)
    at Module._extensions..js (internal/modules/cjs/loader.js:665:10)
    at require.extensions.(anonymous function) (/private/var/folders/_9/37c42sdn1c31kmk9mcp0z9qc0000gn/T/ts-node-dev-hook-9368575770193885.js:57:14)
    at Object.nodeDevHook [as .ts] (/Users/gael/dev/node_modules/ts-node-dev/lib/hook.js:61:7)
    at Module.load (internal/modules/cjs/loader.js:566:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:506:12)
    at Function.Module._load (internal/modules/cjs/loader.js:498:3)
    at Module.require (internal/modules/cjs/loader.js:598:17)
[ERROR] 14:47:11 Error

The error is reported on line 7 instead of line 12. This is a rather simple example but the offset is even bigger in larger files.

I assume this is somehow related to source maps. I would gladly try to open a PR to fix that bug if you can give me any insights on what could be the problem here.

Thanks

Compatibility with tsconfig-paths

running ts-node-dev -r tsconfig-paths/register src/index.ts gives:

./node_modules/resolve/lib/sync.js:19
        throw new TypeError('Path must be a string.');
        ^

TypeError: Path must be a string.
    at module.exports (/Volumes/Extended/Home/Code/mojvix-server/node_modules/resolve/lib/sync.js:19:15)
    at module.exports (/Volumes/Extended/Home/Code/mojvix-server/node_modules/ts-node-dev/lib/resolveMain.js:15:14)
    at Object.<anonymous> (/Volumes/Extended/Home/Code/mojvix-server/node_modules/ts-node-dev/lib/wrap.js:13:12)
    at Module._compile (module.js:624:30)
    at Object.Module._extensions..js (module.js:635:10)
    at Module.load (module.js:545:32)
    at tryModuleLoad (module.js:508:12)
    at Function.Module._load (module.js:500:3)
    at Module.require (module.js:568:17)
    at Function.Module._preloadModules (module.js:725:12)

ts-node -r tsconfig-paths/register src/index.ts works fine. what could be a problem?

pre.24 is really slow and sometimes doesn't trigger restart

After updating to pre.24 I've noticed that my process doesn't restart correctly. Sometimes it just hangs forever and sometimes it will restart, but it will take at least 20 seconds.

When using pre.23 it always restarts and it takes 2-5 seconds max.

For pre.24 it seems to recognize file changes because I see this output:

[INFO] 07:57:47 Restarting: /code/src/controllers/misc.ts has been modified

But then it goes quiet until I restart my Docker container.

Running Windows 10 host with Docker containers on image node:8.11.1. Everything related to node.js is running within the container.

Error: Cannot find module

When I'm importing a custom package which is directing to an .d.ts file, I'm always getting this error.
I have to remove the .d of the file in order to get it work.

Packages like "cookie-session" aren't working, too.

Any Idea?

Thanks

Best regards

Error: Cannot find module 'tsconfig'

module.js:491
    throw err;
    ^

Error: Cannot find module 'tsconfig'
    at Function.Module._resolveFilename (module.js:489:15)
    at Function.Module._load (module.js:439:25)
    at Module.require (module.js:517:17)
    at require (internal/module.js:11:18)

tsconfig is in the usual spot in the root dir. Do I need to do anything special to point it to the right one?

Add an inspect option to enable debugging

I struggle to get ts-node-dev to run the underlying node processes with the --inspect flag. Simply running ts-node-dev --inspect my-script.ts doesn't work.

Looking at previous attempt to fix node arguments it might actually be a bug intorduce in 3ce35a5#diff-20e1c8ba69ac5634c40dadd70e8da65c. If it is not a bug, what about adding a parameter to the command line to enable inspect (and inspect-brk) on the spawn node process? Could be something like node-inspect and node-inpect-brk? It is a matter of prepending the options to nodeArgs array in.bin/ts-node-dev.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.