axios: Cannot find name 'ProgressEvent' when compiling TypeScript

Describe the bug

When trying to compile a Firebase function (Node.js / TypeScript) I get an error:

node_modules/axios/index.d.ts:62:38 - error TS2304: Cannot find name 'ProgressEvent'.

62   onUploadProgress?: (progressEvent: ProgressEvent) => void;
                                        ~~~~~~~~~~~~~

node_modules/axios/index.d.ts:63:40 - error TS2304: Cannot find name 'ProgressEvent'.

63   onDownloadProgress?: (progressEvent: ProgressEvent) => void;
                                          ~~~~~~~~~~~~~

To Reproduce

Example of a package.json that fails to compile using npm run build.

{
  "name": "functions",
  "scripts": {
    "lint": "eslint -c .eslintrc.js --ext .ts ./src",
    "lint-fix": "eslint -c .eslintrc.js --fix --ext .ts ./src",
    "build": "tsc",
    "serve": "npm run build && firebase serve --only functions",
    "shell": "npm run build && firebase functions:shell",
    "start": "npm run shell",
    "firebase": "firebase serve --only functions --port=8080",
    "deploy": "npm run build && npm run lint && firebase deploy --only functions",
    "logs": "firebase functions:log"
  },
  "main": "lib/index.js",
  "dependencies": {
    "axios": "^0.20.0",
    "firebase-functions": "^3.10.0"
  },
  "devDependencies": {
    "@typescript-eslint/eslint-plugin": "^3.9.1",
    "@typescript-eslint/parser": "^3.9.1",
    "eslint": "^7.7.0",
    "eslint-config-prettier": "^6.11.0",
    "eslint-plugin-import": "^2.22.0",
    "eslint-plugin-prettier": "^3.1.4",
    "prettier": "^2.0.5",
    "typescript": "^3.9.7"
  },
  "private": true,
  "engines": {
    "node": "10"
  }
}

Expected behavior

The Node.js code should compile.

Environment

  • Axios Version: 0.20.0
  • Node.js Version: 10.21.0
  • OS: Ubuntu 20.04

Additional context/Screenshots

None.

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 64
  • Comments: 33 (4 by maintainers)

Commits related to this issue

Most upvoted comments

As a quick fix, you can downgrade the axios version by using the following in your package.json:

"dependencies": {
    "axios": "^0.19.0"
}

Make sure to re-run npm install afterwards.

👋 Hey folks, I’d like to suggest to avoid the dependency on lib dom and instead of using a triple-slash directive replace ProgressEvent with its structural equivalent. This will allow Axios types to transpile correctly on both frontend and pure Node.js projects.

Please see my proposal at #3228.

Thanks, Jan

CC: @Guillaume-Mayer, @bennyn

@Mister-Hope In case you don’t need any 0.20.0 features, check out my comment above for a fix.

Just a little curious that nearly half a month has passed, and it’s not fixed yet.

I don’t want to hurt anyone, but leaving the bugs for month in a package with image is not a good idea, I believe there are plenty of typescript users are suffering this problem on pure node env, and have to downgrade back from 0.20.0 while editing their dependency bots(or ci) to prevent upgrading axios.

I don’t think it can be left with other bug fixes and features waiting for the next release. It’s not wrong behavior in certain situation.

It’s a fatal bug for all the typescript users if they are using on a env without DOM, and cannot be bypassed.

This is a bug that presents in TypeScript projects that do not use "lib": [..., "DOM"] (specifically pure node projects), as ProgressEvent is a type that belongs in the DOM builtin library of TypeScript.

Should be solvable by adding triple slash directive pointing to lib="DOM" to the offending file(s) (the files that reference ProgressEvent).

Should be an easy fix for beginners 😃

Are there plans to merge @jan-molak’s proposed PR? Thanks for the work on this.

edit: adding “DOM” to tsconfig “lib” array is a good workaround btw, tested and it appears to work!

Any progress on this one? It’s a critical bug which can not be bypassed if typescript is running on pure node js env.

Hi,

Version 0.21.0 has been released 🎉 please use that and let us know if that solves your issue.

Thanks

Just to update everyone I have asked again today to see when the release will happen, will update this thread as soon as I know whats going on.

Are there plans to merge @jan-molak’s proposed PR? Thanks for the work on this.

edit: adding “DOM” to tsconfig “lib” array is a good workaround btw, tested and it appears to work!

Not with me, including dom will trigger some issues in my project - A pure node env.

Adding “DOM” to the tsconfig lib field works somehow 😃

HI, It will hopefully be released today or over the weekend 😄

Just a little curious that nearly half a month has passed, and it’s not fixed yet.

Now nearly a month passed, and I saw there is already a PR #3228

I am getting this error as of today when trying to build a typescript project (by running tsc)

node_modules/axios/index.d.ts:275:11 - error TS2304: Cannot find name 'ProgressEvent'.

275   event?: ProgressEvent;
              ~~~~~~~~~~~~~


Found 1 error in node_modules/axios/index.d.ts:275
  • Axios version: 1.2.0
  • Node version: 18.12.1
  • tsconfig.json:
{
  "compilerOptions": {
    "sourceMap": true,
    "outDir": "dist",
    "strict": true,
    "lib": ["esnext"],
    "esModuleInterop": true,
    "experimentalDecorators": true,
    "target": "ES6",
    "module": "CommonJS"
  },
  "include": ["src"],
  "ts-node": {
    "files": true
  }
}

Update: A fix has been merged, but not published yet. Try this workaround in the meanwhile.

Version 0.21.0 has been released 🎉 please use that and let us know if that solves your issue.

Upgraded to v0.21.0 and can confirm that we can now build successfully without needing to include the dom library. Thank you!

Please reopen, installed axios today and issue is still present!

I temporary fixed by using the resolution.

// package.json
{
"resolutions": {
    "axios": "^0.19.0"
  }
}

Adding “DOM” to the tsconfig lib field works somehow 😃

This worked like a charm

Please reopen, installed axios today and issue is still present!

It’s fixed so it can be closed, but it’s.not released.

@AuspeXeu Why are you sending me the confused emoji? An issue should be closed the time a linked PR is merged.

Please reopen, installed axios today and issue is still present!

It’s fixed so it can be closed, but it’s.not released.

@sajithneyo it’ll be in the 0.20.1 release I think?! @jasonsaayman

nice …

@Mister-Hope In case you don’t need any 0.20.0 features, check out my comment above for a fix.