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
- Fix #3219 by referencing DOM built-in library Just following @trgwii suggestion. Works for me at least. — committed to Guillaume-Mayer/axios by Guillaume-Mayer 4 years ago
- Fixing #3219 by referencing DOM build-in library Just following @trgwii suggestion. Works for me at least. Triple slash directives are supported from typescript 3 so I updated the dependency to ^3.9... — committed to Guillaume-Mayer/axios by deleted user 4 years ago
- Fixing #3219 by referencing DOM built-in library Just following @trgwii suggestion. Works for me at least. Triple slash directives are supported from typescript 3 so I updated the dependency to ^3.9... — committed to Guillaume-Mayer/axios by deleted user 4 years ago
- Fixing #3219 by copying lib dom definitions I copied the lib dom TS file definitions needed to make the ProgressEvent reference compiling on NodeJS while keeping Typescript 2 compatibility — committed to Guillaume-Mayer/axios by deleted user 4 years ago
- Fixing #3219 by copying lib dom definitions I copied the lib dom TS file definitions needed to make the ProgressEvent reference compile on NodeJS while keeping Typescript 2 compatibility — committed to Guillaume-Mayer/axios by deleted user 4 years ago
- [dep] axios downgrade related to TS issue ref: https://github.com/axios/axios/issues/3219 — committed to MKRhere/craft by MKRhere 4 years ago
- :bug: add dom to tsconfigs. github.com/axios/axios/issues/3219 — committed to acm-uic/registrum by bmiddha 4 years ago
- Downgrade axios due to this TS error - https://github.com/axios/axios/issues/3219 — committed to warrenbuckley/IIS-Express-Code by deleted user 4 years ago
- add 'dom' do tsconfig works around github.com/axios/axios/issues/3219 and allows us to ship again with the latest axios release. Signed-off-by: António Meireles <antonio.meireles@reformi.st> — committed to AntonioMeireles/homebridge-vieramatic by AntonioMeireles 4 years ago
- Revert "Bump dep axios@0.20.0" pending https://github.com/axios/axios/issues/3219 This reverts commit b6f91c563547838551f39426f99902494635b550. — committed to publishlab/node-acme-client by nmorsman 4 years ago
- build: fixes build https://github.com/axios/axios/issues/3219 — committed to ScaleLeap/amazon-advertising-api-sdk by moltar 4 years ago
- Revert broken Axios version. Hitting bug https://github.com/axios/axios/issues/3219 — committed to joshdick/microstat by joshdick 4 years ago
- Downgrade axios to avoid bug https://github.com/axios/axios/issues/3219 — committed to dhutchison/toggl-summary-cli by dhutchison 4 years ago
- Downgrade to axios 0.19.0 Axios 0.20.0 has a bug which prevents typescript builds: https://github.com/axios/axios/issues/3219 — committed to notificationapi-com/notificationapi-node-server-sdk by sahandseifi 4 years ago
- Update Axios version (https://github.com/axios/axios/issues/3219) — committed to felixbade/github-telegram-notifications by felixbade 2 years ago
As a quick fix, you can downgrade the axios version by using the following in your
package.json
: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
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 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.
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 😄
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
)Update: A fix has been merged, but not published yet. Try this workaround in the meanwhile.
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.
This worked like a charm
@AuspeXeu Why are you sending me the confused emoji? An issue should be closed the time a linked PR is merged.
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.