【发布时间】:2022-02-15 21:21:03
【问题描述】:
我已经搜索过堆栈溢出的问题,但仍不清楚为什么会发生这种情况/如何解决。
我想在我的 Typescript 项目中使用节点类型,所以我输入了这个命令:
npm install @types/node --save
导致:
c:/xyz/node_modules/@types/node/index.d.ts(89,13)
error TS2403: Subsequent variable declarations must have the same type.
Variable 'require' must be of type 'Require', but here has type 'NodeRequire'.
我的机器有节点版本 7.0.3 安装的类型是版本 + @types/node@7.0.28
如果我删除卸载类型,我的项目编译没有问题。
似乎根据错误消息输入的内容不正确!修复它很麻烦。有什么建议吗?
似乎需要绕过 NodeRequire(接口)以支持 Require.js?
这是 TSConfig 文件:
{
"compilerOptions": {
"module": "amd",
"moduleResolution": "node",
"target": "es5",
"noImplicitAny": false,
"jsx": "react",
"sourceMap": false,
"baseUrl": ".",
"paths": {
"OfficeFabric/*": [
"node_modules/office-ui-fabric-react/lib-amd/*"
]
}
}
}
我尝试了下面的排除建议,但没有奏效。 Github 说,如果模块解析是 NODE,那么 exclude 无论如何都不起作用。
【问题讨论】:
-
您是否尝试将
"exclude": ["node_modules"]添加到您的tsconfig.json? -
tsconfig.json 已经有 "exclude": ["node_modules"] 行,但我也有同样的问题。
标签: node.js typescript requirejs