node-fetch:不支持的URL类型“node:“:节点:缓冲区

xytpbqjk  于 2023-04-29  发布在  Node.js
关注(0)|答案(3)|浏览(214)

我需要让node-fetch为VUE JS项目工作,但我遇到了这些依赖错误:

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

我尝试run npm install --save node:buffer node:http node:https node:net node:stream node:url node:util node:zlib,但得到了这个错误:
npm ERR!code EUNSUPPORTEDPROTOCOL npm ERR!不支持的URL类型“node:“:节点:缓冲区
如何安装缺少的依赖项?
我使用的是nodejs v16。13.2关于UBUNTU 18.04.6 LTS)

41zrol4v

41zrol4v1#

在不使用(node:)的情况下运行此命令:

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

wnavrhmk2#

对我来说,解决方案是在vue.config.js文件的configureWebpack.external属性中包含'node-fetch':

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

注意事项:您必须将fetch-node安装为yarn add node-fetch@2npm install node-fetch@2(取决于您的包管理器)

w6mmgewl

w6mmgewl3#

只是使用标准的fetch库,我在Vue项目中遇到了一些兼容性问题,卸载node-fetch并使用普通fetch(https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch)解决了这个问题。

相关问题