从 7.0.8 开始,当使用
node_modules/@types/node/index.d.ts(50,14):错误 TS2687:“迭代器”的所有声明必须具有相同的修饰符。
我们的 tsconfig :
{
"compilerOptions": {
"target": "es5",
"module": "amd",
"sourceMap": true,
"strictNullChecks": true,
"noImplicitAny": false,
"noImplicitReturns": true,
"noImplicitThis": false,
"noUnusedParameters": false,
"noUnusedLocals": true,
"experimentalDecorators": false,
"emitDecoratorMetadata": false,
"removeComments": true,
"outFile": "../js/ts.js"
},
"exclude": [
"node_modules",
"../node_modules",
"../../node_modules"
]
}
冲突发生在@types/node 第 50 行和 @types/core-js 第 504 行之间(迭代器:符号)
对我来说也是同样的问题。 配置:
{
"compilerOptions": {
"allowJs": false,
"target": "es5",
"module": "commonjs",
"moduleResolution": "node",
"allowSyntheticDefaultImports": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"sourceMap": true,
"noEmitHelpers": true,
"noUnusedLocals": true,
"noImplicitReturns": true,
"noUnusedParameters": true,
"baseUrl": ".",
"paths": {
"app": [ "src/app" ],
"app/*": [ "src/app/*" ],
"core": [ "src/core" ],
"core/*": [ "src/core/*" ]
},
"typeRoots": [
"node_modules/@types"
]
},
"compileOnSave": false,
"buildOnSave": false,
"exclude": [
"node_modules"
]
}
显然iterator
之前的readonly
修饰符是一个错误。 或者core-js错了。
同样的问题,我所有的构建都在一夜之间坏了。
我们的 tsconfig
{
"compilerOptions": {
"target": "ES5",
"sourceMap": true,
"typeRoots": [ "node_modules/@types/" ],
"noUnusedLocals": true,
"noUnusedParameters": true,
"declaration": false,
"watch": true
},
"compileOnSave": true,
"include": [
"src/**/*"
],
"exclude": [
".vscode",
"node_modules",
"dist"
]
}
也有这个问题。 我们暂时将@types/node 版本修复为 7.0.7,它仍然有效。 在这里发帖主要是为了跟踪问题。
我们也有同样的问题。 打破了一切。
+1 同样的问题。
这里完全一样。
同样在这里,
暂时固定到 7.0.7。
+1 相同
我有同样的问题。
切换回@types/node": "7.0.7"
修复了问题
现在为我工作,删除 core-js 并使用 @types/ [email protected]和 tsconfig: "lib": ["es7"]
同样在这里。 切换回@types/node": "7.0.7" 修复了问题。标记为跟踪进度。
应该由 #15108 修复。 请注意,您可能需要更改 tsconfig 中的“lib”,因为core-js
不再提供诸如Iterator
类的类型。
@andy-ms 你有什么建议我们应该把“lib”改为?
@baywet lib
应该是什么取决于您的项目。 例如,我的项目编译为 ES5,但需要core-js
来填充一些 ES6 功能。 这是我的lib
:
"lib": [
"es6"
"dom"
]
查看编译器选项文档中的--lib
。
我到底应该更改什么文件@types/node": "7.0.7"?
目录搜索显示我有 2 个这样的条目:
我改哪一个,还是两个都改?
这些都在node_modules
,所以大概它们没有被签入并且不能直接更改。 您使用的安装程序工具(例如npm
或jspm
)应该有描述如何安装软件包和设置它们的版本的文档。
但正如上面的讨论所表明的,最好使用所有库的最新版本,并在您的tsconfig.json
正确设置--lib
tsconfig.json
。
正确的安装将在 package.json (s) 中将 ^ 作为第一个字符的版本,以获得最新版本。 关于@types和 libs 的问题,就像这里提到的一般,一旦修复,首先删除所有 node_modules 目录(主项目路径、客户端路径等),然后在每个相关目录中执行 npm install,然后再次启动 tsc(通常使用 grunt 或等效的构建文件),以检查一切是否正常。
在预生产和生产环境中,您可能必须这样做。
@harrietsCreativeDabblets您应该能够在项目的 devDependencies 中包含以下内容(在ng-start/package.json
):
"@types/node": "7.0.7"
由于这满足jspm-config
semver,它将确保您的@types/node
被锁定到7.0.7
。 请注意,如果这不满足jspm-config
semver,您最终会得到重复的定义。
确保在修改项目 package.json 后删除node_modules
和npm i
。
@pe8ter感谢您的精确。 我最终升级到@types/ [email protected]并在我的 tsconfig.json 中进行了这些更改,从而保持了 IE11 兼容性。
"lib": [
"dom",
"dom.iterable",
"es2015",
"scripthost"
],
同样的问题在这里; 7.0.7 版本降级解决
同样的问题在这里; 7.0.7 版本降级解决
看起来这个问题没有解决,永远使用 7.0.7 版本是不合逻辑的。 此外,固定版本并没有为我解决这个问题。 此线程中没有任何内容。
@loctrice node_modules/typescript/package.json
的 TypeScript 版本和node_modules/@types/node/package.json
节点版本是什么?
打字稿是 2.3.4,节点是 8.0.5
@loctice我无法用这些版本重现这个。 我在一个空白目录中,刚刚安装了那些。 你的tsconfig
什么? 你能试着得到一个小的复制品吗?
顺便说一句,你的意思是8.0.50
而不是8.0.5
吗? 两者都测试过,没有出错。
我不确定我的 tsconfig 应该是什么。 从旧类型升级到@types 后,我一直在讨论这个问题,所以我一直在根据我看到的线程对其进行更改,只是看看是否有任何工作。 这是我的最后一个错误,在今天早些时候之前我根本没有输入任何库。 我添加的任何内容都没有产生效果:
{
“编译器选项”:{
“目标”:“es5”,
“模块”:“系统”,
"moduleResolution": "节点",
“源地图”:假,
“emitDecoratorMetadata”:真,
"experimentalDecorators": 真,
"removeComments": 真,
“noImplicitAny”:假,
“类型根”:[
“./node_modules/@types”
],
“库”:[
"es2015",
"es6",
"dom",
“dom.iterable”
]
},
我无法用那些已安装的版本和tsconfig.json
重现错误。
}
)npm install @types/[email protected] [email protected]
echo "" > a.ts
node node_modules/typescript/lib/tsc.js
这有助于我开始解决问题。 我将开始一次添加一个类型,以查看我的 angular2 项目中的问题所在。
看起来这可能是由我安装的 core-js 和 es6 类型引起的。 如果我删除 core-js,那么我昨天通过将 core-js 的版本固定到 0.9.35 修复了诸如“Promise 是一种类型”之类的功能的错误。 这是我的打字:
柴:“^4.0.4”,
核心js:“0.9.35”,
节点:“^8.0.50”,
开放层:“^4.1.0”,
systemjs: "^0.20.6",
看起来冲突是因为在第 504 行的 core-js 中有iterator: symbol
的定义,而在第 54 行的节点类型中有readonly iterator: symbol
的定义,将其中任何一个手动更改为match 将使我的项目编译。
我正在尝试更新angular2-electron-boilerplate并
node_modules/@types/node/index.d.ts(79,14): error TS2687: All declarations of 'iterator' must have identical modifiers.
79 readonly iterator: symbol;
~~~~~~~~
phil<strong i="9">@Loki</strong> ~/d/g/s/g/o/angular2-electron-boilerplate (master) [130]>
grep -rnE 'iterator:\s+symbol' node_modules/
node_modules//@types/node/index.d.ts:79: readonly iterator: symbol;
node_modules//typescript/lib/lib.es2015.iterable.d.ts:28: readonly iterator: symbol;
node_modules//typescript/lib/lib.es6.d.ts:4763: readonly iterator: symbol;
node_modules//reflect-metadata/Reflect.ts:95: declare const Symbol: { iterator: symbol, toPrimitive: symbol };
版本:
@philipbel你弄明白了吗?
@loctice描述的问题是否有永久修复?
不,我没有。
2018 年 1 月 2 日 2:11,Smackzter [email protected]写道:
@philipbel你弄明白了吗?
—
你收到这个是因为你被提到了。
直接回复此邮件,在 GitHub 上查看,或将线程静音。
@philipbel看起来问题出在reflect-metadata
。 很好奇你是如何用Reflect.ts
而不是Reflect.d.ts
编译的。
@loctice通过手动编辑 core-js 我的项目可以编译但是我们有更好的解决方案吗?
尝试使用@ types/ [email protected]效果很好
@thanhngvpt我不参与这个项目,所以我无法提供解决方案。 我最终被迫升级了我的项目,并且使用了大部分软件包,一切似乎都很好。
为了解决这个
npm i [email protected] --save
我的构建是从哪里坏掉的!! 仍然显示此问题。
我的环境
Ionic:
Ionic CLI : 5.2.3 (C\\\\node_modules\ionic)
Ionic Framework : ionic-angular 3.9.5
@ionic/app-scripts : 3.2.2
Cordova:
Cordova CLI : 8.0.0
Cordova Platforms : android 8.0.0
Cordova Plugins : cordova-plugin-ionic-keyboard 2.1.3, cordova-plugin-ionic-webview 4.1.1, (and 20 other plugins)
Utility:
cordova-res : 0.8.1
native-run : 1.0.0
System:
Android SDK Tools : 26.1.1 (C:\\\\AppData\Local\Android\Sdk)
NodeJS : v10.15.3 (C:\Program Files\nodejs\node.exe)
npm : 6.4.1
OS : Windows 10
Typescript is 2.5
是的,我所做的一切似乎都无法解决这个问题。 我的tsconfig.json
没有lib
定义,我完全被这个线程中提供的信息弄糊涂了。 这是我的tsconfig.json
文件:
{
"compilerOptions": {
"target": "es6",
"module": "commonjs",
"moduleResolution": "node",
"rootDir": "src",
"outDir": "out",
"forceConsistentCasingInFileNames": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"pretty": true,
"declaration": true
}
}
我应该怎么做才能停止产生以下我完全无法控制的编译器错误?
node_modules/vscode/vscode.d.ts:534:3 - error TS2687: All declarations of 'textEditor' must have identical modifiers.
534 textEditor: TextEditor;
~~~~~~~~~~
node_modules/vscode/vscode.d.ts:8363:3 - error TS2687: All declarations of 'body' must have identical modifiers.
8363 body?: any;
~~~~
依赖项:
"devDependencies": {
"@types/node": "^8.10.59",
"@types/vscode": "^1.1.36",
"rimraf": "^3.0.0",
"tslint": "^5.20.1",
"tslint-config-xo": "^2.0.0",
"typescript": "^3.7.4",
"vscode": "^1.1.36"
}
似乎将"skipLibCheck": true
到我的tsconfig.json
消除了编译器错误。 不过,我不确定不对使用过的库进行类型检查是否是个好主意。
{
"compilerOptions": {
"skipLibCheck": true
}
}
最有用的评论
@harrietsCreativeDabblets您应该能够在项目的 devDependencies 中包含以下内容(在
ng-start/package.json
):"@types/node": "7.0.7"
由于这满足
jspm-config
semver,它将确保您的@types/node
被锁定到7.0.7
。 请注意,如果这不满足jspm-config
semver,您最终会得到重复的定义。确保在修改项目 package.json 后删除
node_modules
和npm i
。