2017-03-11 122 views
16

我想在一個項目上運行的WebPack和我得到了多個錯誤找不到名稱「PROPERTYKEY」

node_modules/@types/core-js/index.d.ts 
error TS2304: Cannot find name 'PropertyKey'. 
... 
node_modules/@types/core-js/index.d.ts 
error TS2339: Property 'for' does not exist on type 'SymbolConstructor'. 

我應該安裝所有的分型,所以我不知道在哪裏,這些都來自哪裏。我試圖從一個編譯的項目拷貝package.json,但它沒有幫助。我錯過了什麼?

我tsconfig看起來像這樣

{ 
    "compilerOptions": { 
    "target": "es5", 
    "emitDecoratorMetadata": true, 
    "experimentalDecorators": true, 
    "sourceMap": true, 
    "noImplicitAny": false, 
    "suppressImplicitAnyIndexErrors": true 
    }, 
    "include": [ 
    "src/**/*" 
    ], 
    "exclude": [ 
    "node_modules", 
    "**/*.spec.ts" 
    ] 
} 

回答

34

我收到同一樣的錯誤與@類型/核心JS在0.9.35

可能是別的東西..

編輯

已經有在回購一些變化上個星期。您可以通過以下鏈接閱讀GitHub上的問題,看到了變化:

https://github.com/DefinitelyTyped/DefinitelyTyped/issues/15104

https://github.com/DefinitelyTyped/DefinitelyTyped/pull/15108/commits/f2c5c990e448550fcebec071c25e6a1e5766dde7

我的解決辦法是改變

"lib": ["es5", "dom"]"lib": ["es6", "dom"]compilerOptions對象在我tsconfig文件。

通過這樣做,我所犯的錯誤,而不降級到0.9.35

注意消失:你不需要改變目標(我仍然ES5)

+0

它適合我。但是,我有兩臺電腦運行VS2015 Pro與最新的更新和包,一個有問題,可以通過這個答案解決,而另一個不需要。有點奇怪。 – ZZZ

+0

也許你沒有在正確的位置查找tsconfig?或者,也許有一個有升級版本的類型,另一個有另一個。 – Jackie

+2

更改爲ES6不會中斷IE 11操作嗎?換句話說,ES6和瀏覽器合規性的後果是什麼? – Brandon

5

降級@types/core-js到0.9.35。

升級到0.9.37後,我只是遇到同樣的問題。

+0

我將我的版本降級到0.9.36,它工作。感謝:D –

2

可以確認裝載版本0.9.35解決了這個問題爲了我。

"devDependencies": { 
    ... 
    "@types/core-js": "0.9.35", 
    ... 
} 
7

對我來說,答案是...

"compilerOptions": { 
    ... 
    "lib": [ 
    "es2016", 
    "dom" 
    ] 
}, 
2

降級爲 「@類型/核心JS」: 「^ 0.9.35」,並增加lib添加到我的compilerOptions。 {

"experimentalDecorators": true, 
"moduleResolution": "node", 
    "lib": ["es2017", "dom"] //Please add this code in your tsconfig.json 

}:

"devDependencies": { 
    "@types/core-js": "^0.9.35", 
    ...... 
} 

tsconfig.json

{ 
"compilerOptions": { 
    ........ 
    "lib": [ 
     "es2016", 
     "dom" 
    ] 
}, 
"exclude": [ 
    "node_modules", 
    ... 
] 
} 
+0

添加「@ types/core-js」後:「^ 0.9.35」,是否需要運行npm命令?像npm更新什麼的? 這仍然不適合我。 – Sam

2

我在tsconfig.json添加該代碼

{ 「compilerOptions」 解決我的問題, 「排除」 :[ 「node_modules」 ] }