ts-node ignores d.ts files while tsc successfully compiles the project

前端 未结 4 585
伪装坚强ぢ
伪装坚强ぢ 2021-02-03 17:20

Having compiled my TypeScript project successfully, I intended to run it in VS Code\'s debug mode using ts-node. Problem is, ts-node can\'t find

相关标签:
4条回答
  • 2021-02-03 17:51

    I was having a similar problem, but I could not add --files, because I run ts-node by registering the module through mocha (i.e. mocha -r ts-node/register ...).

    I could solve it by adding a files and a ts-node section to tsconfig.json like this:

    // tsconfig.json
    {
      "ts-node": {
        "files": true
      },
      "files": [
        "src/index.ts",
        "src/global.d.ts"
      ],
      "compilerOptions":{
        //...
      }
    }
    

    I hope somebody will find this useful.

    0 讨论(0)
  • 2021-02-03 17:56

    ts-node --files src/boot.ts

    ts-node in 7.0.0, default do not Load files from tsconfig.json on startup, you should specific --files

    0 讨论(0)
  • 2021-02-03 18:01

    Here's How i fixed it. Add "nodemon --exec ts-node --files src/app.ts" to your dev script.

     "scripts": {
        "start": "node dist/app.js",
        "dev": "nodemon --exec ts-node --files src/app.ts",
        "build": "tsc -p",
        "test": "echo \"Error: no test specified\" && exit 1"
      },
    
    0 讨论(0)
  • 2021-02-03 18:03

    I spent way to much time on this issue tried almost everything like adding to typeRoots my typings folder, creating typing folder with structure typings/module/index.d.ts but nothing worked out so now I've figured it out now what the above answer meant

    With a new version of ts-node I've changed for my project's scripts:

    ts-node@6: ts-node src/index.ts
    ts-node@7: ts-node --files src/index
    

    So your script will be changed to something like below

    "scripts": {
        "dev": "nodemon --exec ts-node --files src/index",
      }
    

    With the above in action your compile time increase a lot but I couldn't spend more time on this so I'm sticking to the above.

    You also might like to visit https://github.com/TypeStrong/ts-node#help-my-types-are-missing.

    0 讨论(0)
提交回复
热议问题