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

our project used Angular6 and typescript 2.9.2。
after @types/node upgrading to 14.6.3 , npm build failed with error,

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

// NOTE: TypeScript version-specific augmentations can be found in the following paths:
// - ~/base.d.ts - Shared definitions common to all TypeScript versions
// - ~/index.d.ts - Definitions specific to TypeScript 2.1
// - ~/ts3.2/index.d.ts - Definitions specific to TypeScript 3.2
// Reference required types from the default lib:
/// <reference lib="es2015" />

reference lib is add in typescript 3.0, not worked in typescript 2.x

16 Answers

✔️Accepted Answer

This was the same issue for us and we fixed it by using a fixed version (14.6.2) of @types/node in our devDependencies in the package.json.

{
  "name": "some-library",
  "version": "1.2.3",
  "description": "Some library",
  "files": [
    "lib"
  ],
  "main": "lib/index.js",
  "scripts": {
  },
  "devDependencies": {
    "@types/node": "14.6.2",
    "ts-node": "^8.0.2",
    "typescript": "^2.9.1"
  },
  "dependencies": {
    "@types/long": "^4.0.0",
    "long": "^4.0.0"
  },
  "engines": {
    "node": "~10"
  }
}

Other Answers:

This is because DefinitelyTyped no longer supports TypeScript 2, as per the support table in the readme.

You'll have to update to TypeScript 3.2 or above to be able to consume the latest version of @types/node :)

I can say the same with types/node 11.15.21. Our project stopped building today and we had to freeze the version on 11.15.20. There are more errors found than that one. Here is the list that broke our build in case it is helpful. We are not using TS 3 either.

node_modules/@types/node/assert.d.ts(2,68): error TS1144: '{' or ';' expected.
node_modules/@types/node/assert.d.ts(22,68): error TS1144: '{' or ';' expected.
node_modules/@types/node/assert.d.ts(31,94): error TS1144: '{' or ';' expected.
node_modules/@types/node/assert.d.ts(31,101): error TS1005: ';' expected.
node_modules/@types/node/assert.d.ts(31,104): error TS1005: ';' expected.
node_modules/@types/node/assert.d.ts(33,98): error TS1144: '{' or ';' expected.
node_modules/@types/node/assert.d.ts(33,105): error TS1005: ';' expected.
node_modules/@types/node/assert.d.ts(33,108): error TS1005: ';' expected.
node_modules/@types/node/assert.d.ts(41,47): error TS1144: '{' or ';' expected.
node_modules/@types/node/assert.d.ts(41,53): error TS1005: ';' expected.
node_modules/@types/node/assert.d.ts(41,56): error TS1005: ';' expected.
node_modules/@types/node/base.d.ts(10,1): error TS1084: Invalid 'reference' directive syntax.
node_modules/@types/node/base.d.ts(11,1): error TS1084: Invalid 'reference' directive syntax.
node_modules/@types/node/base.d.ts(12,1): error TS1084: Invalid 'reference' directive syntax.
node_modules/@types/node/base.d.ts(13,1): error TS1084: Invalid 'reference' directive syntax.
node_modules/@types/node/ts3.6/base.d.ts(10,1): error TS1084: Invalid 'reference' directive syntax.
node_modules/@types/node/ts3.6/base.d.ts(11,1): error TS1084: Invalid 'reference' directive syntax.
node_modules/@types/node/ts3.6/base.d.ts(12,1): error TS1084: Invalid 'reference' directive syntax.
node_modules/@types/node/ts3.6/base.d.ts(13,1): error TS1084: Invalid 'reference' directive syntax.

According to README:

@types packages have tags for versions of TypeScript that they explicitly support, so you can usually get older versions of packages that predate the 2-year window. For example, if you run npm dist-tags @types/react, you'll see that TypeScript 2.5 can use types for react@16.0, whereas TypeScript 2.6 and 2.7 can use types for react@16.4:

This means, if you have TypeScript 3.1 or older, you should use older versions of @types/node as indicated by NPM tags.

I can say the same with types/node 11.15.21. Our project stopped building today and we had to freeze the version on 11.15.20. There are more errors found than that one. Here is the list that broke our build in case it is helpful. We are not using TS 3 either.

node_modules/@types/node/assert.d.ts(2,68): error TS1144: '{' or ';' expected.
node_modules/@types/node/assert.d.ts(22,68): error TS1144: '{' or ';' expected.
node_modules/@types/node/assert.d.ts(31,94): error TS1144: '{' or ';' expected.
node_modules/@types/node/assert.d.ts(31,101): error TS1005: ';' expected.
node_modules/@types/node/assert.d.ts(31,104): error TS1005: ';' expected.
node_modules/@types/node/assert.d.ts(33,98): error TS1144: '{' or ';' expected.
node_modules/@types/node/assert.d.ts(33,105): error TS1005: ';' expected.
node_modules/@types/node/assert.d.ts(33,108): error TS1005: ';' expected.
node_modules/@types/node/assert.d.ts(41,47): error TS1144: '{' or ';' expected.
node_modules/@types/node/assert.d.ts(41,53): error TS1005: ';' expected.
node_modules/@types/node/assert.d.ts(41,56): error TS1005: ';' expected.
node_modules/@types/node/base.d.ts(10,1): error TS1084: Invalid 'reference' directive syntax.
node_modules/@types/node/base.d.ts(11,1): error TS1084: Invalid 'reference' directive syntax.
node_modules/@types/node/base.d.ts(12,1): error TS1084: Invalid 'reference' directive syntax.
node_modules/@types/node/base.d.ts(13,1): error TS1084: Invalid 'reference' directive syntax.
node_modules/@types/node/ts3.6/base.d.ts(10,1): error TS1084: Invalid 'reference' directive syntax.
node_modules/@types/node/ts3.6/base.d.ts(11,1): error TS1084: Invalid 'reference' directive syntax.
node_modules/@types/node/ts3.6/base.d.ts(12,1): error TS1084: Invalid 'reference' directive syntax.
node_modules/@types/node/ts3.6/base.d.ts(13,1): error TS1084: Invalid 'reference' directive syntax.

i am facing this issue now what is the solution for this issue, i changed the node/types version also its not working any suggestion..

More Issues: