javascript - 安装本地节点类型时的重复标识符
问题描述
我正在尝试tsc
在一个项目上运行,但我收到一条错误消息,指出有两个重复的标识符URL
和URLSearchParams
.
我在全球范围内安装了打字稿,在我的项目中我有@types/node
.
但是,当我@types/node
在项目中安装时,我会收到此错误:
../../../../../.nvm/versions/node/v10.0.0/lib/node_modules/typescript/lib/lib.es2016.full.d.ts(13404,11): error TS2300: Duplicate identifier 'URL'.
../../../../../.nvm/versions/node/v10.0.0/lib/node_modules/typescript/lib/lib.es2016.full.d.ts(13420,13): error TS2300: Duplicate identifier 'URL'.
../../../../../.nvm/versions/node/v10.0.0/lib/node_modules/typescript/lib/lib.es2016.full.d.ts(13427,11): error TS2300: Duplicate identifier 'URLSearchParams'.
../../../../../.nvm/versions/node/v10.0.0/lib/node_modules/typescript/lib/lib.es2016.full.d.ts(13454,13): error TS2300: Duplicate identifier 'URLSearchParams'.
../../../../../.nvm/versions/node/v10.0.0/lib/node_modules/typescript/lib/lib.es2016.full.d.ts(15740,13): error TS2300: Duplicate identifier 'URL'.
../../../../../.nvm/versions/node/v10.0.0/lib/node_modules/typescript/lib/lib.es2016.full.d.ts(15741,13): error TS2300: Duplicate identifier 'URLSearchParams'.
../../../../../.nvm/versions/node/v10.0.0/lib/node_modules/typescript/lib/lib.es2016.full.d.ts(16503,11): error TS2300: Duplicate identifier 'URLSearchParams'.
node_modules/@types/node/index.d.ts(2381,15): error TS2300: Duplicate identifier 'URL'.
node_modules/@types/node/index.d.ts(2399,15): error TS2300: Duplicate identifier 'URLSearchParams'.
node_modules/@types/node/index.d.ts(2417,14): error TS2661: Cannot export 'URL'. Only local declarations can be exported from a module.
node_modules/@types/node/index.d.ts(2417,19): error TS2661: Cannot export 'URLSearchParams'. Only local declarations can be exported from a module.
不知道出了什么问题以及为什么我收到此错误。
如果我node types
从我的项目中删除 ,我会在其他依赖项中收到一个错误,指出它找不到net
,http
等:
node_modules/@types/uuid/interfaces.d.ts(1,23): error TS2688: Cannot find type definition file for 'node'.
node_modules/@types/uuid/interfaces.d.ts(4,48): error TS2304: Cannot find name 'Buffer'.
node_modules/@types/uws/index.d.ts(7,23): error TS2688: Cannot find type definition file for 'node'.
node_modules/@types/uws/index.d.ts(10,23): error TS2307: Cannot find module 'http'.
node_modules/@types/uws/index.d.ts(11,24): error TS2307: Cannot find module 'https'.
node_modules/@types/uws/index.d.ts(12,22): error TS2307: Cannot find module 'net'.
tsconfig.json
{
"compilerOptions": {
"target": "es2016",
"module": "system",
"strict": true,
"outFile": "../../lib/client/red5.js",
"sourceMap": true,
"declaration": true
},
"include": [
"./Connector.ts",
"**/*.ts"
]
}
package.json中的依赖项
"dependencies": {
"@types/get-port": "^3.2.0",
"@types/node": "^10.0.0",
"@types/uuid": "^3.4.3",
"@types/uws": "^0.13.2",
"get-port": "^3.2.0",
"uuid": "^3.2.1",
"uws": "^9.148.0"
},
"devDependencies": {
"uglify-es": "^3.3.9"
}
解决方案
如 Node.js 10 变更日志中所述,URL
现在URLSearchParams
可以在全球范围内使用以模仿浏览器中的环境:
https://github.com/nodejs/node/commit/312414662b
所以我敢打赌,类型定义@types/node
还不是最新的,无法正确考虑这种变化。
推荐阅读
- java - 使用Java检查序列是否几乎严格按升序排列
- python - 在集合和字典中使用输入(Python)
- python - 在 Python Pynput 中使用 Key.f5 时,key.char 给出 AttributeError
- android - Google Play 服务位置 API 简单代码不起作用
- django - 根据 ChoiceField 选择启用/禁用 Django 表单字段?
- php - 通过where href 包含一个保存图像内容的 php 变量下载图像
- xamarin.forms - Xamarin.Forms.VideoPlayer 捕获
- html - Edge 不显示背景颜色的十六进制代码
- typescript - 如何将 RxJs 6 与 TypeScript 和 WebPack 一起使用
- function - 一次调用一个序列中的所有元素的函数xquery