Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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"

like image 241
heyJoe Avatar asked Sep 03 '20 09:09

heyJoe


4 Answers

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

and remove the third slash

// <reference lib="es2015" />

compile again

like image 57
Morfing Avatar answered Nov 16 '22 15:11

Morfing


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

like image 26
Belle S Rao Avatar answered Nov 16 '22 15:11

Belle S Rao


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.

like image 19
sda87 Avatar answered Nov 16 '22 13:11

sda87


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

like image 6
Richard Andres Cardozo Lemus Avatar answered Nov 16 '22 14:11

Richard Andres Cardozo Lemus