30

Have anyone been in this situation before ? I run my code with CI/CD after nest build, it gives me error : node_modules/@types/superagent/index.d.ts:23:10 - error TS2305: Module '"buffer"' has no exported member 'Blob'. 23 import { Blob } from "buffer";

I don't know why? Please share if you got a solution for this one.

ninoorta
  • 662
  • 1
  • 5
  • 13
  • looks like this is related with the version of your `@types/node` or something like that – Micael Levi Jan 26 '22 at 03:27
  • 1
    It is so weird because yesterday everything is still fine to me :( . I still use the same node version with it. – ninoorta Jan 26 '22 at 03:50
  • have you versioned the lock file and ran `npm ci`? – Micael Levi Jan 26 '22 at 04:03
  • I will try it now. But when I run in local , it is still good? only when I push it to gitlab and run CI/CD , it gives me this error. Have you ever got something like this before ? – ninoorta Jan 26 '22 at 04:12
  • 1
    I haven't. I've been using GitHub Actions in TS projects without worries so far. Maybe the version that your CI/CD end up having isn't the same as the local one due to the lack of the lock file and `npm ci` – Micael Levi Jan 26 '22 at 16:13
  • Yes, I got your point. But it seems like the answer from @vfrank66 is the answer I need. – ninoorta Jan 27 '22 at 01:23
  • Thank you @MicaelLevi . Your comments are so helpful – ninoorta Jan 27 '22 at 02:17

5 Answers5

50

We had the same problem after upgrading nest 7.5.x to 8.0.0. The dependency "supertest" for "nestjs/testing" has a dependency on "@types/supertest" which wildcards "@types/superagent": "*", and that dependency has another wildcard dependency "@types/node": "*", but the types within @types/supertest actually require @types/node >=16.X.X.

So nestjs/testing -> supertest -> @types/supertest -> @types/superagent -> @types/node >= 16.X.X is your problem and error.

The comments mentioned are accurate because these package managers wildcard their dependencies to get the latest version of dependencies. They should but do not add peerDependencies with dependencies requirements such as "@types/node": "">=12.0.0 <16.0.0". Instead they say anything, "@types/node": "*" so the error is post package install, no npm warnings/errors. "It worked yesterday but not today" is your big red flag because when you ran npm install, with these wildcard dependencies even though you did not know it installed the latest version. Since it installed everything wildcard today, but not yesterday, it worked yesterday.

In addition, but also important is that you are have pinned @types/node <16.0.0 thus your error in combination with the other package changes.

One option: revert your package-lock.json changes and run npm ci

Another option: set your package.json dependency for @types/node to -> "@types/node": "^16.0.0",.

Another option: accept that wildcards are wrong and you don't trust what is going on there so pin the @types/superagent dependency to the one prior.

As for me and my family, we use nestjs with AWS lambda which runtime does not include nodejs 16, and not everyone on my team runs npm ci we more typically run npm install so the solution was

package.json

    ...
    "devDependencies": {
        ...
        "@types/node": "14.18.2",
        "@types/superagent": "4.1.10",
        "@types/supertest": "^2.0.11",
        ...

vfrank66
  • 1,318
  • 19
  • 28
12

Upgrading @types/node to ^14.18.10 and typescript to ^3.9.10 worked for me.

"devDependencies": {
  "@types/node": "^14.18.10",
  "typescript": "^3.9.10"
},

Found on this discussion from Github

Hugo Sohm
  • 2,872
  • 4
  • 23
  • 40
3

downgrading @types/superagent from v15.x.x to 14.1.14 solved the issue for me. v15 had some performance issues at the typing of this message "npm i --save @types/superagent@4.1.14" did the trick

2

One tip is use npm view to get some info.

If you type

npm view @types/node

That shows the ts version compatibility. In my case, Is had to upgrade @types/node to 14.14.31, because I'm using ts 3.4.2.

Akostha
  • 679
  • 7
  • 8
1

if you have installed the npm, then delete the node_module file and use yarn install to add the new node_module and vice versa.