Ts-node: Ignoring "exclude" from tsconfig.json

Created on 12 Oct 2016  Â·  12Comments  Â·  Source: TypeStrong/ts-node

I'm pretty sure ts-node is ignoring the exclude option in tsconfig.json. I get no errors when using tsc directly.

tsconfig.json

{
    "compileOnSave": false,
    "compilerOptions": {
        "target": "es5",
        "allowJs": true,
        "module": "commonjs",
        "moduleResolution": "node",
        "sourceMap": true,
        "emitDecoratorMetadata": true,
        "experimentalDecorators": true,
        "removeComments": false,
        "noImplicitAny": false,
        "types": [
            "node"
        ]
    },
    "exclude": [
        "node_modules",
    ]
}

ts-node main.ts

~/.nvm/versions/node/v6.7.0/lib/node_modules/ts-node/src/index.ts:308
          throw new TSError(diagnosticList)
                ^
TSError: ⨯ Unable to compile TypeScript
node_modules/json-schema/lib/validate.js (43,10): Duplicate identifier 'validate'. (2300)
node_modules/json-schema/lib/validate.js (68,5): Duplicate identifier 'validate'. (2300)
    at getOutput (~/.nvm/versions/node/v6.7.0/lib/node_modules/ts-node/src/index.ts:308:17)
    at ~/.nvm/versions/node/v6.7.0/lib/node_modules/ts-node/src/index.ts:334:18
    at Object.compile (~/.nvm/versions/node/v6.7.0/lib/node_modules/ts-node/src/index.ts:488:17)
    at Module.m._compile (~/.nvm/versions/node/v6.7.0/lib/node_modules/ts-node/src/index.ts:392:44)
    at Module._extensions..js (module.js:565:10)
    at Object.require.extensions.(anonymous function) [as .js] (~/.nvm/versions/node/v6.7.0/lib/node_modules/ts-node/src/index.ts:395:12)
    at Module.load (module.js:473:32)
    at tryModuleLoad (module.js:432:12)
    at Function.Module._load (module.js:424:3)
    at Module.require (module.js:483:17)

Also I know there is a duplicate identifier error in json-schema but using tsc main.ts and then node main.js works correctly with no changes.

bug

Most helpful comment

Ok, I found the issue. Since 1.4.0, the added --ignore option (which could override the default node_modules ignore) was faulty - which resulted in it ignoring nothing and compiling node_modules files (a behaviour previously avoided on purpose). I've fixed the flag with 1.6.0. Let me know if that works for you 😄

How did you added it, It doesn't work for me. can you provide an example? thanks

All 12 comments

You should probably look up howtsc works when you're specifying the files on the CLI. When you do that, it wouldn't be using the config file. Does this still occur when you do compile using the config file?

Also, the config file you posted is invalid JSON which also makes me believe it's not used.

@blakeembrey Sorry for the invalid config, I was trying a few different things before I posted.

Here is an updated one.

{
    "compileOnSave": false,
    "compilerOptions": {
        "target": "es5",
        "allowJs": true,
        "module": "commonjs",
        "moduleResolution": "node",
        "outDir": "dist",
        "sourceMap": true,
        "emitDecoratorMetadata": true,
        "experimentalDecorators": true,
        "removeComments": false,
        "noImplicitAny": false
    },
    "include": [
        "src/**/*"
    ],
    "exclude": [
        "node_modules"
    ]
}

Also thanks for the pointer on specifying files. I realized it loads my config file and runs properly when doing tsc && node ./dist/main.js.

Can you share an example project so that I can replicate it? How did you get around the module import error of json-schema?

It just worked when I used tsc directly. I also got around it by using the -D flag with ts-node but I opted to use tsc && node ./dist/main.js instead so I could see warnings in my own code.

I'll try making an example project later today. I have to get something else fixed right now.

Ok, thank you. I can't seem to compile with tsc either so I can't tell if there's something else I'm missing.

I am having a similar error. It breaks at versions 1.2.3 and later but works at 1.2.2. I will try to make a repro.

/Users/jperl/dev/test-proj/node_modules/ts-node/dist/index.js:158
                    throw new TSError(formatDiagnostics(diagnosticList, cwd, ts, lineOffset));
                    ^
TSError: ⨯ Unable to compile TypeScript
node_modules/knex/node_modules/bluebird/js/release/util.js (201,5): Unreachable code detected. (7027)

@jperl Thanks. I'm not sure it's related, but this module _should_ be ignoring node_modules. ts-node doesn't use the exclude option from tsconfig.json directly - only indirectly for definition loading. I'll take a look at why that's not being ignored.

Ok, I found the issue. Since 1.4.0, the added --ignore option (which could override the default node_modules ignore) was faulty - which resulted in it ignoring nothing and compiling node_modules files (a behaviour previously avoided on purpose). I've fixed the flag with 1.6.0. Let me know if that works for you 😄

That fixed it. Thank you!

Ok, I found the issue. Since 1.4.0, the added --ignore option (which could override the default node_modules ignore) was faulty - which resulted in it ignoring nothing and compiling node_modules files (a behaviour previously avoided on purpose). I've fixed the flag with 1.6.0. Let me know if that works for you 😄

How did you added it, It doesn't work for me. can you provide an example? thanks

Was this page helpful?
0 / 5 - 0 ratings

Related issues

max-block picture max-block  Â·  4Comments

nehalist picture nehalist  Â·  3Comments

KiaraGrouwstra picture KiaraGrouwstra  Â·  3Comments

cevek picture cevek  Â·  4Comments

aj-r picture aj-r  Â·  3Comments