5

I need to get node-fetch working for a VUE JS project but I ran into these dependencies errors:

These dependencies were not found:

* node:buffer in ./node_modules/node-fetch/src/index.js, ./node_modules/node-fetch/src/body.js
* node:http in ./node_modules/node-fetch/src/index.js, ./node_modules/node-fetch/src/headers.js
* node:https in ./node_modules/node-fetch/src/index.js
* node:net in ./node_modules/node-fetch/src/utils/referrer.js
* node:stream in ./node_modules/node-fetch/src/index.js, ./node_modules/node-fetch/src/body.js
* node:url in ./node_modules/node-fetch/src/request.js
* node:util in ./node_modules/node-fetch/src/body.js, ./node_modules/node-fetch/src/headers.js and 1 other
* node:zlib in ./node_modules/node-fetch/src/index.js

To install them, you can run: npm install --save node:buffer node:http node:https node:net node:stream node:url node:util node:zlib

I tried to run npm install --save node:buffer node:http node:https node:net node:stream node:url node:util node:zlib but got this error:

npm ERR! code EUNSUPPORTEDPROTOCOL npm ERR! Unsupported URL Type "node:": node:buffer

How to install the missing dependencies?

(I'm using NODE JS v16.13.2 on UBUNTU 18.04.6 LTS)

Tom
  • 5,588
  • 20
  • 77
  • 129
  • 3
    So, the `node:` protocol prefix for built-in modules was added to nodejs v16.0.0 and v14.18.0. I'd suggest you make absolutely sure that you're really running the nodejs v16.13.2 that you think you are because the error makes it sound like you're actually running an older version of node. You could probably also get a slightly older version of `node-fetch` that doesn't use those prefixes. – jfriend00 Jan 28 '22 at 03:21

3 Answers3

1

run this command without (node:):

npm install --save buffer http https net stream url util zlib
Aous Mohammad
  • 802
  • 2
  • 16
1

Just use the standard fetch library, I had some compatibility issues with a Vue project and uninstalling node-fetch and just using normal fetch (https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch) solved it.

0

The solution for me was to include 'node-fetch' in the vue.config.js file at the configureWebpack.external property:

module.exports = {
    configureWebpack: {
        externals: {
            'node-fetch': "require('node-fetch')"
        }
    }
}

IMPORTANT: You have to install fetch-node as yarn add node-fetch@2 or npm install node-fetch@2 (depending of your package manager)