Reputation: 5958
I have typescript compilation setup, and compiling works perfectly.
I then install jest
(a testing framework) as a devDependency
. This is for development only (hence why it is a devDependency
), and shouldn't be part of the compiled package.
Compilation now results in the following error:
node_modules/@types/babel__template/index.d.ts:16:28 - error TS2583: Cannot find name 'Set'. Do you need to change your target library? Try changing the `lib` compiler option to es2015 or later.
16 placeholderWhitelist?: Set<string>;
Can this error be solved, and if so, how? Adding "lib": ["es6"]
is not am acceptable solution, as an implementation details of jest should not require me to modify my compiler options like this. Also note that jest
runs perfectly. If there is no other solution, then that's an acceptable answer.
Why is tsc
compiling devDependencies
and how do I stop this? I don't see why I should suddenly have to worry about the nested babel devDependency
affecting my compilation.
Edit: tsconfig.json
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"sourceMap": true,
"rootDir": "./src",
"outDir": "./build",
"strict": true,
"esModuleInterop": true
},
"include": [
"src/**/*"
],
"exclude": [
"/src/**/?(*.)test.ts"
]
}
Note: This is not a duplicate of node_modules/@types/babel _template/index.d.ts :16:28 - error TS2583: Cannot find name 'Set'
This question was asking why tsc is looking in node_modules
which is different from my questions (and the accepted answer is for that question).
Upvotes: 3
Views: 923
Reputation: 141462
Why is tsc compiling devDependencies and how do I stop this? I don't see why I should suddenly have to worry about the nested babel devDependency affecting my compilation.
By default, tsc
loads all the declarations in node_modules/@types/**/*
, which in your case, includes a type declaration that depends on >= es2015
. If that type declaration came from a devDependency
, then tsc
will include it. That's why tsc
is compiling something associated with a devDependency
.
If upgrading to es2015
is not a valid solution, then you can also try ignoring the specific type declaration that depends on it.
From the TypeScript documentation on @types:
By default all visible “@types” packages are included in your compilation... Specify
"types": []
to disable automatic inclusion of@types
packages.
Upvotes: 2
Reputation: 1004
Considering your tsconfig
you can:
add lib
to your compilerOptions
, but you don't want impact your project because of a test lib, I understand that;
make sure your tests use another tsconfig
, like a tsconfig.test.json
which have the needed lib
=> I think it's your solution;
Upvotes: 1