node_modules/@types/node/index.d.ts(20,1): error TS1084: Invalid 'reference' directive syntax
Asked Answered
L

9

49

I have a problem with typescript compilation. Has anybody else received this error?

node_modules/@types/node/index.d.ts(20,1): error TS1084: Invalid 'reference' directive syntax.

tsconfig.json:

{
    "compileOnSave": false,
    "compilerOptions": {
        "sourceMap": true,
        "outDir": "./dist",
        "rootDir": "./app",
        "target": "es6",
        "module": "commonjs",
        "declaration": false,
        "noImplicitAny": false,
        "removeComments": true,
        "emitDecoratorMetadata": true,
        "experimentalDecorators": true,
        "listFiles": false,
        "skipLibCheck": true
    },
    "include": [
        "./app/**/*.ts"
    ]
}

typescript version in package.json: "typescript": "^2.6.1"

Leprechaun answered 3/9, 2020 at 9:12 Comment(0)
A
52

Had the same issue. Open the file ../node_modules/@types/node/index.d.ts

and remove the third slash

// <reference lib="es2015" />

compile again

Acquisition answered 20/9, 2020 at 9:9 Comment(6)
But next time you clear node_modules and reinstall, or install on another machine, this is gone and you'll need to remember to do this again...Procrustes
You can remove third slash but as it is less advisable to change the content of any node_modules folder, better update the typescript version to latest one.Spondee
I had problems with my testing, after hours of searching, this works like a charm =)Olympic
downgrading to "@types/node": "^7.0.7" looks like more wise solutionAddressograph
Before: /// <reference lib="es2015" /> After: // <reference lib="es2015" />Argentine
don't offer fake solutions. editing bundle files is never a good solution. it will be override at the first deployment or npm iFilagree
B
38

I got the same error. I used the pinned version "@types/node": "7.0.7" in my package.json and got it working.

Bursary answered 3/9, 2020 at 11:14 Comment(1)
I updated my package.json with "@types/node": "7.0.7" and then ran the following: npm install --save @types/node. After that I was able to run npm start successfully. Thanks!Auklet
S
22

I have faced the same problem and found the solution is to update typescript to the latest version from the current version.

Make changes in the package.json file like below:

"devDependencies": {
     "typescript": "^3.9.7"
 }

Now "npm install typescript" , it will upgrade to latest version. Then run "ng serve" and it will compile successfully.

Spondee answered 12/1, 2021 at 6:26 Comment(0)
X
10

update TypeScript

npm install typescript@latest --save-dev
Xavier answered 30/10, 2021 at 7:18 Comment(2)
it works, basically needs to update tSAlbania
It is the most suitable answer. It works for me as well.Beery
B
8

Its worked for me ckeckout your tags for versions of TypeScript. run npm dist-tag ls @types/node and look for your currently typescript version.

Then install the @types/node version supporting for typescript in my case I had to install 14.0.1 version

reference: https://github.com/DefinitelyTyped/DefinitelyTyped/issues/47250#issuecomment-687701880

Behan answered 15/2, 2021 at 18:25 Comment(0)
B
3

Had the same error and the fix was to use the previous version, check the version that you have in package.json for @types/node and see if you have the latest or not. You can check here: https://www.npmjs.com/package/@types/node as it seams that there was a new update.

Beady answered 3/9, 2020 at 10:33 Comment(1)
Gave you the vote up since you beat the answer above by more than a half hour, and it is better practice to update to the latest version (assuming the issue is fixed) than it is to just build to a specific version. Also, I do not understand why all of the answers recommending to update typescript are getting upvoted when the issue is obviously with @types/node.Heatstroke
A
1

My solution is to change typescript version to '>=2.7.3'. I think the version might depend on other packages. probably need to try a couple of times to get the right version. And don't forget to run install.

Adversity answered 6/1, 2021 at 20:56 Comment(0)
C
0

Try downgrading the @type/node.

I had the same issue with

"devDependencies": {
    "@types/node": "12.20.42",
}

I downgraded it to lower version and it compiles successfully

"devDependencies": {
    "@types/node": "12.19.12",
}
Cuman answered 9/2, 2022 at 13:30 Comment(0)
L
-3

I have faced the same problem and found the solution is to update typescript to the latest version from the current version.

Make changes in the package.json file like below:

"devDependencies": {
     "typescript": "^3.9.7"
 }

Now npm install typescript, it will upgrade to the latest version. Then run "ng serve" and it will compile successfully.

Lunneta answered 15/1, 2021 at 15:41 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.