【发布时间】:2017-12-22 07:16:41
【问题描述】:
将我的 Typescript 版本从 2.3.x 升级到 2.4.1 后,我遇到了以下错误:
ERROR in *path*/tsconfig.json
error TS2688: Cannot find type definition file for 'mocha'.
是我的项目配置错误还是需要以某种方式更新这些类型?类型肯定仍然存在,它们必须被 TypeScript 2.4 以不同的方式引用?
这是我的 package.json:
{
"scripts": {
...
"build": "rimraf dist && npm run build:client && npm run build:server",
...
"build:client": "cross-env NODE_ENV=production webpack --config build/webpack.client.config.js --progress --hide-modules",
"build:server": "cross-env NODE_ENV=production webpack --config build/webpack.server.config.js --progress --hide-modules",
...
},
"engines": {
"node": ">=7.0",
"npm": ">=4.0"
},
"dependencies": {
...
},
"devDependencies": {
"@types/chai": "4.0.1",
"@types/express": "4.0.36",
"@types/jquery": "2.0.48",
"@types/mocha": "2.2.41",
"@types/node": "7.0.32",
...
"chai": "4.1.0",
...
"typescript": "2.4.1",
...
"vue-ts-loader": "0.0.3",
"webpack": "3.2.0",
"webpack-dev-middleware": "1.11.0",
"webpack-hot-middleware": "2.18.2",
"webpack-merge": "4.1.0",
"webpack-node-externals": "1.6.0",
"webpack-shell-plugin": "0.5.0"
}
}
这是我的 tsconfig.json:
{
"compilerOptions": {
"allowSyntheticDefaultImports": true,
"target": "es5",
"module": "es2015",
"moduleResolution": "node",
"noImplicitAny": true,
"noImplicitReturns": true,
"noUnusedLocals": true,
"sourceMap": true,
"experimentalDecorators": true,
"outDir": "out/",
"allowJs": true,
"lib": [
"dom",
"es5",
"es2015.promise"
]
},
"exclude": [
"node_modules",
"dist",
"test"
]
}
【问题讨论】:
-
貌似是known issue
-
远射:尝试在 tsconfig 中设置类型。我对 mocha 使用 this one,但设置一个空数组可能也足够了。
-
我建议你尝试打字并使用 typeRoots": ["/typings/"]。npm 中的类型已经过时了。
-
谢谢@k0pernikus。我没有使用 ts-loader (这似乎已经修复),但也许 vue-ts-loader 有同样的问题。我会调查的。
-
以下问题为我指明了正确的方向:stackoverflow.com/questions/40885537/…
标签: typescript webpack mocha.js definitelytyped