Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot find name 'ProgressEvent' when compiling TypeScript #3219

Closed
claust opened this issue Aug 21, 2020 · 33 comments · Fixed by #3237
Closed

Cannot find name 'ProgressEvent' when compiling TypeScript #3219

claust opened this issue Aug 21, 2020 · 33 comments · Fixed by #3237
Projects
Milestone

Comments

@claust
Copy link

claust commented Aug 21, 2020

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.

@trgwii
Copy link

trgwii commented Aug 21, 2020

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 :)

@FlorianPfisterer
Copy link

FlorianPfisterer commented Aug 21, 2020

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.

Guillaume-Mayer added a commit to Guillaume-Mayer/axios that referenced this issue Aug 22, 2020
Just following @trgwii suggestion.
Works for me at least.
Guillaume-Mayer pushed a commit to Guillaume-Mayer/axios that referenced this issue Aug 22, 2020
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.7
this might be a breaking change
Guillaume-Mayer pushed a commit to Guillaume-Mayer/axios that referenced this issue Aug 22, 2020
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.7
this might be a breaking change
@Guillaume-Mayer
Copy link

@trgwii as a beginner I tried to solve the issue following your suggestion. Unfortunately triple slash directives are only supported from Typescript v3. So, I'm not confident it will be merged. I may try to give it another attempt by copying the definition from the lib dom file into the axios definition file, this should work too I guess.

Guillaume-Mayer pushed a commit to Guillaume-Mayer/axios that referenced this issue Aug 22, 2020
I copied the lib dom TS file definitions needed
to make the ProgressEvent reference compiling on
NodeJS while keeping Typescript 2 compatibility
Guillaume-Mayer pushed a commit to Guillaume-Mayer/axios that referenced this issue Aug 22, 2020
I copied the lib dom TS file definitions needed
to make the ProgressEvent reference compile on
NodeJS while keeping Typescript 2 compatibility
MKRhere added a commit to MKRhere/craft that referenced this issue Aug 22, 2020
@jan-molak
Copy link

jan-molak commented Aug 25, 2020

👋 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
Copy link

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

@FlorianPfisterer
Copy link

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

@Mister-Hope
Copy link

@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.

@Kryshtopenko
Copy link

nice ...

bmiddha added a commit to acm-uic/registrum that referenced this issue Sep 7, 2020
@mvogel-dev
Copy link

mvogel-dev commented Sep 7, 2020

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!

@jasonsaayman
Copy link
Member

Hi @AuspeXeu,

At the moment only Emily can do this, Nick and Matt could but they are not actively maintaining the project as they handed over to Emily. I know Emily is pretty busy with stuff but I do have direct communication with her and the release is planned to go out in the next few days.

@AuspeXeu
Copy link

Ah, sweet. Given how many people rely on axios, it might be good if you also have this sort of authorization. Maybe worth mentioning it to her :)

@g14a
Copy link

g14a commented Oct 18, 2020

Adding "DOM" to the tsconfig lib field works somehow :)

@tomcanac
Copy link

Hi,

Thanks for the great library and the work, it's really appreciated to be able to have this library up and running 🎉!
We are hitting this bug since our last package update, do you have any news about the publishing of the latest fix?

Thanks, really appreciated!

sahandseifi added a commit to notificationapi-com/notificationapi-node-server-sdk that referenced this issue Oct 21, 2020
Axios 0.20.0 has a bug which prevents typescript builds:

axios/axios#3219
@jasonsaayman
Copy link
Member

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.

@Mister-Hope
Copy link

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.

@emmanuelagarry
Copy link

Adding "DOM" to the tsconfig lib field works somehow :)

This worked like a charm

@jasonsaayman
Copy link
Member

Hi,

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

Thanks

@jasonsaayman jasonsaayman added this to the v0.21.0 milestone Oct 23, 2020
@jasonsaayman jasonsaayman added this to To do in v0.21.0 via automation Oct 23, 2020
@jasonsaayman jasonsaayman moved this from To do to Done in v0.21.0 Oct 23, 2020
@alexpls
Copy link

alexpls commented Oct 24, 2020

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!

@pSnehanshu
Copy link

pSnehanshu commented Dec 2, 2022

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.

@thinktapper
Copy link

I also had this error today & am happy to share that the fix has been merged as of v1.2.1. Updating fixed it for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
v0.21.0
  
Done
Development

Successfully merging a pull request may close this issue.