Reputation: 615
I'm working on a back-end powered by Node, using Babel and Typescript, and Jest (with ts-jest) for testing.
Everything worked great until 2 days ago, my testing is not working anymore, instead I get
error TS2688: Cannot find type definition file for [module name]
This error happens for every module in my node_modules folder which doesn't have a .d.ts file in it. Here are the first few lines of the error for you to see :
FAIL src/entity/OfferPool.test.ts
● Test suite failed to run
TypeScript diagnostics (customize using `[jest-config].globals.ts-jest.diagnostics` option):
error TS2688: Cannot find type definition file for '.bin'.
error TS2688: Cannot find type definition file for '.cache'.
error TS2688: Cannot find type definition file for '@babel'.
error TS2688: Cannot find type definition file for '@types'.
error TS2688: Cannot find type definition file for 'abab'.
error TS2688: Cannot find type definition file for 'abbrev'.
error TS2688: Cannot find type definition file for 'accepts'.
error TS2688: Cannot find type definition file for 'acorn'.
error TS2688: Cannot find type definition file for 'acorn-globals'.
error TS2688: Cannot find type definition file for 'acorn-walk'.
I also get this error for every test file I have.
Do you know where this can be from ? It was working well a few days ago...
Here are a few config files that can help :
For Typescript :
//tsconfig.json
{
"compilerOptions": {
"module": "commonjs",
"declaration": true,
"noImplicitAny": false,
"removeComments": true,
"allowSyntheticDefaultImports": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"target": "es6",
"sourceMap": true,
"outDir": "./dist",
"baseUrl": "./src",
"lib": ["es2015"],
"moduleResolution": "node",
"noEmitHelpers": true,
"importHelpers": true,
"strict": true,
"noImplicitReturns": true,
"typeRoots": [
"node_modules"
]
},
"include": [
"./src/**/*",
"./src/**/*.test.ts"
],
"exclude": [
"./node_modules"
]
}
For Babel :
//.babelrc
{
"presets": ["@babel/preset-typescript", "@babel/preset-env"],
"plugins": ["@babel/plugin-proposal-class-properties"]
}
For Jest :
// jest.config.js
module.exports = {
preset: "ts-jest",
testEnvironment: "node",
};
And my dependencies :
"dependencies": {
"@babel/polyfill": "^7.0.0",
"@types/es6-promise": "^3.3.0",
"@types/node": "^10.12.10",
"aws-sdk": "^2.188.0",
"bluebird": "^3.5.1",
"cookie-parser": "~1.4.3",
"cors": "^2.8.4",
"debug": "~2.6.9",
"dotenv": "^6.1.0",
"express": "~4.16.0",
"express-fileupload": "^0.4.0",
"express-winston": "^2.6.0",
"helmet": "^3.9.0",
"http-errors": "~1.6.2",
"jade": "~1.11.0",
"jwt-simple": "^0.5.1",
"moment": "^2.20.1",
"morgan": "~1.9.0",
"mysql": "^2.15.0",
"node-fetch": "^2.3.0",
"tslib": "^1.9.3",
"winston": "^3.1.0"
},
"devDependencies": {
"@babel/cli": "^7.1.2",
"@babel/core": "^7.1.2",
"@babel/node": "^7.0.0",
"@babel/plugin-proposal-class-properties": "^7.1.0",
"@babel/plugin-proposal-object-rest-spread": "^7.0.0",
"@babel/preset-env": "^7.1.6",
"@babel/preset-typescript": "^7.1.0",
"@types/express": "^4.16.0",
"@types/jest": "^23.3.9",
"@types/node-fetch": "^2.1.4",
"babel-eslint": "^8.2.6",
"babel-jest": "^23.6.0",
"jest": "^23.6.0",
"nodemon": "^1.18.1",
"ts-jest": "^23.10.5",
"typescript": "^3.1.3"
}
Upvotes: 3
Views: 8659
Reputation: 1810
I don't think you are using typeRoots
correctly. This may solve your problem, https://www.typescriptlang.org/docs/handbook/tsconfig-json.html the default is to use node_modules/@types
.
Upvotes: 2