node-fetch: Unsupported URL Type "node:": node:buffer
Asked Answered
F

3

6

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)

Fordone answered 27/1, 2022 at 20:22 Comment(1)
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.Carlson
T
1

run this command without (node:):

npm install --save buffer http https net stream url util zlib
Thuthucydides answered 27/1, 2022 at 20:25 Comment(1)
Just tried it but still get the same error. Any ideas what else I could try?Fordone
R
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)

Ratio answered 13/7, 2022 at 17:10 Comment(0)
Y
0

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.

Yeta answered 23/4, 2023 at 11:9 Comment(1)
Thanks! deleted using "npm uninstall node-fetch" and then "npm install fetch". Worked like charm.Gablet

© 2022 - 2024 — McMap. All rights reserved.