19

I am trying to run Webpack on a project and I am getting multiple errors

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'.

I should have all my typings installed so I am not sure where these are coming from. I tried copying over a package.json from a project that compiles but it didn't help. What am I missing?

My tsconfig looks like this

{
  "compilerOptions": {
    "target": "es5",
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "sourceMap": true,
    "noImplicitAny": false,
    "suppressImplicitAnyIndexErrors": true
  },
  "include": [
    "src/**/*"
  ],
  "exclude": [
    "node_modules",
    "**/*.spec.ts"
  ]
}
Jackie
  • 21,969
  • 32
  • 147
  • 289

6 Answers6

38

I am getting the same kind of errors with @types/core-js at 0.9.35

Could be something else..

EDIT

There has been some changes on the repo last week. You can read the issue on github and see the changes via these links:

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

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

My solution was to change

"lib": ["es5", "dom"] to "lib": ["es6", "dom"] in the compilerOptions object in my tsconfig files.

By doing this I made the errors disappear without downgrading to 0.9.35

Note: You dont need to change the target (mine is still es5)

msanford
  • 11,803
  • 11
  • 66
  • 93
Kemal Yalcinkaya
  • 1,818
  • 1
  • 13
  • 25
  • it works for me. However, I have 2 computers both running VS2015 Pro with latest update and packages, one had problem which could be fixed by this answer, and the other does not need. A bit strange. – ZZZ Mar 14 '17 at 12:57
  • Maybe one is not looking in the right place to the tsconfig? Or maybe one had the upgraded version of the types and one had another. – Jackie Mar 16 '17 at 18:30
  • 2
    Does changing to ES6 not break IE 11 operation? In other words what are the ramifications in regards to ES6 and browser compliance? – Brandon Apr 07 '17 at 15:42
  • 2
    as long as the target is still es5, your code should be able to run in IE. – ZZZ Apr 08 '17 at 22:39
8

For me the answer was...

"compilerOptions": {
  ...
  "lib": [
    "es2016",
    "dom"
  ]
},
Jackie
  • 21,969
  • 32
  • 147
  • 289
5

downgrade your @types/core-js to 0.9.35.

I was just having the same problem after upgrading to 0.9.37.

Saar Kuriel
  • 572
  • 4
  • 16
2

Can confirm loading version 0.9.35 fixed this for me.

"devDependencies": {
    ...
    "@types/core-js": "0.9.35",
    ...
}
BrrBr
  • 965
  • 1
  • 8
  • 16
2

Downgraded to "@types/core-js": "^0.9.35" and added lib to my compilerOptions.

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

tsconfig.json

{
"compilerOptions": {
    ........
    "lib": [
        "es2016",
        "dom"
    ]
},
"exclude": [
    "node_modules",
    ...
]
}
Mani S
  • 2,501
  • 1
  • 12
  • 12
  • After you add "@types/core-js": "^0.9.35", do you need to run an npm command? like npm update or something? This is still not working for me. – Sam Jul 30 '17 at 12:53
  • I removed the 'npm_modules' folder using this [link](https://stackoverflow.com/questions/21122342/how-to-clean-node-modules-folder-of-packages-that-are-not-in-package-json/45269399#45269399) and then again ran command 'npm install' – Akshay May 13 '18 at 18:13
2

I solved my problem by adding this code in tsconfig.json

{ "compilerOptions": {

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

}, "exclude": [ "node_modules" ] }

DKR
  • 5,426
  • 1
  • 19
  • 21