在某些Node.js版本上出现TypeScript“找不到声明文件”错误

时间:2018-09-06 22:17:36

标签: node.js typescript

我正在尝试为现有的TypeScript项目设置"noImplicitAny": true选项。进行所有必要的代码更改之后,对于节点6和7的依赖项之一,我得到以下错误:

Could not find a declaration file for module '@firebase/database'. '/home/travis/build/firebase/firebase-admin-node/node_modules/@firebase/database/dist/index.node.cjs.js' implicitly has an 'any' type.

这在Node 8(本地和Travis CI)上都可以正常工作。

有人知道这是为什么吗?我可以理解该错误,但不知道为什么它仅在某些版本的Node上发生。

修改

添加了traceResolution选项,我确实看到在节点7和8之间解析依赖性的方式有所不同。

在节点8上:

'package.json' has 'typings' field 'dist/index.d.ts' that references '/home/travis/build/firebase/firebase-admin-node/node_modules/@firebase/database/dist/index.d.ts'.
File '/home/travis/build/firebase/firebase-admin-node/node_modules/@firebase/database/dist/index.d.ts' exist - use it as a name resolution result.
Resolving real path for '/home/travis/build/firebase/firebase-admin-node/node_modules/@firebase/database/dist/index.d.ts', result '/home/travis/build/firebase/firebase-admin-node/node_modules/@firebase/database/dist/index.d.ts'.
======== Module name '@firebase/database' was successfully resolved to '/home/travis/build/firebase/firebase-admin-node/node_modules/@firebase/database/dist/index.d.ts'. ========

在节点7上:

'package.json' has 'typings' field 'dist/index.d.ts' that references '/home/travis/build/firebase/firebase-admin-node/node_modules/@firebase/database/dist/index.d.ts'.
File '/home/travis/build/firebase/firebase-admin-node/node_modules/@firebase/database/dist/index.d.ts' does not exist.
Loading module as file / folder, candidate module location '/home/travis/build/firebase/firebase-admin-node/node_modules/@firebase/database/dist/index.d.ts', target file type 'TypeScript'.
File '/home/travis/build/firebase/firebase-admin-node/node_modules/@firebase/database/dist/index.d.ts.ts' does not exist.
...
File '/home/travis/build/firebase/firebase-admin-node/node_modules/@firebase/database/dist/index.node.cjs.js' exist - use it as a name resolution result.
Resolving real path for '/home/travis/build/firebase/firebase-admin-node/node_modules/@firebase/database/dist/index.node.cjs.js', result '/home/travis/build/firebase/firebase-admin-node/node_modules/@firebase/database/dist/index.node.cjs.js'.
======== Module name '@firebase/database' was successfully resolved to '/home/travis/build/firebase/firebase-admin-node/node_modules/@firebase/database/dist/index.node.cjs.js'. ========

0 个答案:

没有答案