node-fetch: Unsupported URL Type "node:": node:buffer

Viewed 1311

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)

2 Answers

run this command without (node:):

npm install --save buffer http https net stream url util zlib

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)

Related