我想在 Typescript 项目中使用 npm 模块,但是这个模块没有 typings 或 tsd。当我尝试使用 import Module from 'module'
时出现错误:Cannot find module 'module'.
有办法修复吗?
[编辑]
我的 tsconfig.json
:
{
"compilerOptions": {
"target": "ES5",
"moduleResolution": "node",
"module": "commonjs",
"noEmitOnError": true,
"noImplicitAny": true,
"experimentalDecorators": true,
"sourceMap": true,
"sourceRoot": "src",
"outDir": "bld"
},
"exclude": [
"bld"
]
}
最佳答案
我假设你的问题与导入模块有关
import Module from 'module'
并没有像您所说的那样导出它。如果是这种情况,您可以退回到普通的 javascript 并像这样需要模块:
var Module = require('module');
[编辑]
验证在 tsconfig.json 中您在编译器选项中有以下几行:
"compilerOptions": {
"moduleResolution": "node",
"module": "commonjs"
}
希望这对您有所帮助。
关于typescript - 在 Typescript 中使用 npm 模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36309361/