在项目中使用 tsconfig 运行 tsc --watch 时,出现以下错误。 它需要 Node js 中的 React 和 Redux 类型。
error TS2688: Cannot find type definition file for 'abstract-leveldown'.
The file is in the program because:
Entry point for implicit type library 'abstract-leveldown'
error TS2688: Cannot find type definition file for 'bn.js'.
The file is in the program because:
Entry point for implicit type library 'bn.js'
error TS2688: Cannot find type definition file for 'body-parser'.
The file is in the program because:
Entry point for implicit type library 'body-parser'
error TS2688: Cannot find type definition file for 'connect'.
The file is in the program because:
Entry point for implicit type library 'connect'
error TS2688: Cannot find type definition file for 'debug'.
The file is in the program because:
Entry point for implicit type library 'debug'
error TS2688: Cannot find type definition file for 'express'.
The file is in the program because:
Entry point for implicit type library 'express'
error TS2688: Cannot find type definition file for 'express-jwt'.
The file is in the program because:
Entry point for implicit type library 'express-jwt'
error TS2688: Cannot find type definition file for 'express-serve-static-core'.
The file is in the program because:
Entry point for implicit type library 'express-serve-static-core'
error TS2688: Cannot find type definition file for 'express-unless'.
The file is in the program because:
Entry point for implicit type library 'express-unless'
error TS2688: Cannot find type definition file for 'firebase'.
The file is in the program because:
Entry point for implicit type library 'firebase'
error TS2688: Cannot find type definition file for 'graceful-fs'.
The file is in the program because:
Entry point for implicit type library 'graceful-fs'
请解释为什么会发生这种情况。 我是否已经在 Github 中设置了该项目。
我卸载了node js和npm并重新安装,仍然有同样的问题。然后我注意到有一个 npm 和 npm-cache 文件夹以及 node_modules 文件夹,卸载不会删除。当我删除它们并重新安装节点时,瞧!我的代码开始工作。我敢打赌,node_modules 可能有罪。
当我切换分支但忘记重新安装 npm 软件包时,就发生了这种情况。所以这样做:
npm install
在当前分支中,然后重试。
当我重新克隆我的项目时,这发生在我身上。您需要安装 node_modules 文件夹,因为它未提交到存储库。
在包含 tsconfig.json 文件的目录中执行
npm install
。
如果错误仍然显示,请重新启动 IDE,问题应该可以解决。
在我的例子中,类似的错误是由其中一个包的内部依赖关系产生的。我只是在 package-lock.json 中搜索了
PACKAGE_NAME
来找出哪个包包含那个坏的 PACKAGE_NAME
包,然后将我找到的包升级到最新版本。
(其中 PACKAGE_NAME
是错误中的包的名称)。
当我在这个问题中寻找解决方案时,这可能会对某人有所帮助。