代码之家  ›  专栏  ›  技术社区  ›  kk651

React UnhandledSchemaError-插件未处理“node:buffer”

  •  0
  • kk651  · 技术社区  · 4 年前

    我正在尝试在我的React项目中使用一个包,该包将允许我进行API调用(axios、node-fotch、get等) 如果未安装这些软件包,应用程序将正常运行。当它们中的任何一个被安装并在代码中调用时,我将面临如下错误:

    enter image description here

    忽略这些警告,我认为问题的根源在于以下输出:

    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 节点版本:16.15.0

    0 回复  |  直到 4 年前
        1
  •  1
  •   Nicolas Bouvrette    3 年前

    您可以使用此Webpack配置解决此问题:

    plugins: [
      new webpack.NormalModuleReplacementPlugin(/node:/, (resource) => {
        resource.request = resource.request.replace(/^node:/, "");
      }),
    ]