Ts-node: Correct usage with TS2 and @types/node

Created on 19 Aug 2016  路  11Comments  路  Source: TypeStrong/ts-node

I've installed @types/node and ts2 beta (locally and globally)

If I do tsc path/to/file.ts (or node ./node_modules/typescript/bin/tsc path/to/file.ts) it compiles ok, so no need in placing path to node typings in files. But ts-node requires it.

I use ts-node using register hook and can not find typings for node while run. So I have to place: "node_modules/@types/node/index.d.ts" in files of tsconfig.json and then it works.

Is it expected? Why it should it be configured this way?

Most helpful comment

Hello, Windows 10 64 bit here. Using typescript 2.0.3 and ts-node 1.3.0

I got this working by using the types key under compilerOptions in tsconfig.json

Here is an example tsconfig.json I'm using to run mocha tests via npm with the following script: "mocha --compilers ts:ts-node/register,tsx:ts-node/register \"./src/**/*.spec.ts\""

{
    "compilerOptions": {
        ...
        "types": [
          "node",
          "mocha",
          "chai",
          ...
        ]
    },
    "include": [
      "./src/**/*.ts",
      "./src/**/*.tsx"
    ],
    "exclude": [
      "node_modules",
      "./src/**/*.spec.ts"
    ]
}

All 11 comments

Can you provide the versions you're using?

That would be why. You need to update.

This is the PR (https://github.com/TypeStrong/ts-node/pull/150) that should have enabled support. Let me know if that fixes things for you.

Seems the issue persist with 1.3.0, in tsconfig I only have exclude (or files).

@whitecolor Are you using Windows? Could be the same issue as https://github.com/TypeStrong/ts-node/issues/168 - I haven't resolved that yet.

Yes i'm using windows, ts-node doesn't lookup typings in node_modules/@types (the same problem I experience with webpack's ts-loader)

It works on Unix as far as I know, so it's not that.

Hello, Windows 10 64 bit here. Using typescript 2.0.3 and ts-node 1.3.0

I got this working by using the types key under compilerOptions in tsconfig.json

Here is an example tsconfig.json I'm using to run mocha tests via npm with the following script: "mocha --compilers ts:ts-node/register,tsx:ts-node/register \"./src/**/*.spec.ts\""

{
    "compilerOptions": {
        ...
        "types": [
          "node",
          "mocha",
          "chai",
          ...
        ]
    },
    "include": [
      "./src/**/*.ts",
      "./src/**/*.tsx"
    ],
    "exclude": [
      "node_modules",
      "./src/**/*.spec.ts"
    ]
}

I got this working by using the types key under compilerOptions in tsconfig.json

That works.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

dakom picture dakom  路  3Comments

Borewit picture Borewit  路  3Comments

motss picture motss  路  4Comments

sodiumjoe picture sodiumjoe  路  4Comments

OliverJAsh picture OliverJAsh  路  3Comments