20
node_modules/axios/index.d.ts:93:12 - error TS2304: Cannot find name 'AbortSignal'.

93   signal?: AbortSignal;
              ~~~~~~~~~~~


Found 1 error.

When trying npm run build comand for node typescript project, i am getting above error, something related to axio package. before axio usage, npm run build working fine.

MUHAMMAD SHAHID RAFI C P
  • 1,067
  • 1
  • 12
  • 25

4 Answers4

34

You need to add DOM to the lib array in your tsconfig.json:

"lib": [
      "es2018",
      "DOM"
    ],
caveman_dick
  • 6,302
  • 3
  • 34
  • 49
  • 1
    I just downgrade axios package, now the issue resolved, can you detail about your solution, what will happen when i put above mentioned code on tsconfig.json ? – MUHAMMAD SHAHID RAFI C P Nov 27 '21 at 17:33
  • 3
    As it's just type hints nothing other than fixing your build issue. Here is the axios issue for this https://github.com/axios/axios/issues/4124. FYI upgrading to nodejs 16 will also fix it. – caveman_dick Nov 29 '21 at 18:54
  • Updating @types/node also helps: https://github.com/serenity-js/serenity-js/issues/1223#issuecomment-1145415886 – Artur Trzop Jun 06 '22 at 18:59
8

You could also add "skipLibCheck": true, to your tsconfig.json under compilerOptions. This will ignore errors that are present in libs under node_modules

vlio20
  • 8,955
  • 18
  • 95
  • 180
1

If you're working on node.js code and don't want to introduce a dependency on dom in your tsconfig.json (incorrect in the context of backend code), use this solution instead.

Cannot find name 'AbortSignal'. is a regression in Axios, which has been fixed on master, but never released - see Axios#4229.

However, based on Axios#4304 (comment), you can see that @alecgibson updated @types/node module to introduce AbortController and AbortSignal in DefinitelyTyped#58270, to reflect its support since Node.js 14.7.0.

To address the issue in Axios, make sure to update @types/node to a recent ^14 release or newer.

Solution originally posted in Serenity/JS#1223

Jan Molak
  • 4,426
  • 2
  • 36
  • 32
  • updated `@types/node` to v14 and it still doesn't work – dragonfly02 Aug 24 '22 at 03:52
  • @dragonfly02 - You'd need at least 14.7.0, but nowadays (Aug 2022) Node.js 16 is the Long-Term Support version, and it also has support for `AbortSignal`. Hope this helps! – Jan Molak Aug 26 '22 at 14:29
0

You can also downgrade ts version to "typescript": "~4.8.2" on devDependencies sections in package.json file and run npm i again.

B.Habibzadeh
  • 490
  • 6
  • 10