Cannot find name 'AbortSignal' during npm run build

Viewed 5307
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.

3 Answers

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

"lib": [
      "es2018",
      "DOM"
    ],

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

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

Related