我正试图在我的React项目中使用一个能够允许我进行API调用的软件包(如axios、node-fetch、got等)。当这些软件包未安装时,应用程序可以正常运行。但是,当其中任何一个被安装并在代码中调用时,我会面临以下错误:
忽略这些警告,我认为问题的根源来自下面的输出:
Failed to compile.
Module build failed: UnhandledSchemeError: Reading from "node:buffer" is not handled by plugins (Unhandled scheme).
Webpack supports "data:" and "file:" URIs by default.
You may need an additional plugin to handle "node:" URIs.
我已经尝试了各种方法。重新安装 node_modules。创建了一个干净的测试应用程序并在那里尝试。我还进行了研究,但没有找到任何相关且清晰的解决方案。没有什么帮助。
我做错了什么??
DomException 文件内容:
/*! node-domexception. MIT License. Jimmy Wärting <https://jimmy.warting.se/opensource> */
if (!globalThis.DOMException) {
try {
const { MessageChannel } = require('worker_threads'),
port = new MessageChannel().port1,
ab = new ArrayBuffer()
port.postMessage(ab, [ab, ab])
} catch (err) {
err.constructor.name === 'DOMException' && (
globalThis.DOMException = err.constructor
)
}
}
module.exports = globalThis.DOMException
npm版本:8.5.5 node版本:16.15.0