【问题标题】:How i can solve Electron error: "Buffer is not defined"?我如何解决电子错误:“缓冲区未定义”?
【发布时间】:2022-07-08 08:20:41
【问题描述】:

我正在 emberjs 上开发一个应用程序,并使用电子作为桌面版本。

我连接了eosjs-ecc插件并查看了它的来源,我意识到它使用了Buffer,但是出现了“Buffer is not defined”这个错误。

我尝试了几个选项,其中 webPreferences: { nodeIntegration: true } 这也无济于事。

有人解决了类似的问题吗?感谢您的回答!

【问题讨论】:

    标签: javascript ember.js electron add-on


    【解决方案1】:

    由于Buffer 在网络上不可用,您需要对其进行填充。

    由于现代 ember 使用 webpack,polyfilling Buffer 有据可查。这是开箱即用的list of plugins webpack。

    如果你只使用 ember-auto-import,在你的 ember-cli-build.js 中,你会像这样提供你的 webpack 配置:

    // ember-cli-build.js
    
    // ...
    
    let app = new EmberApp(defaults, {
      // ...
      autoImport: {
        webpack: {
          plugins: [
            new webpack.ProvidePlugin({
              Buffer: ['buffer', 'Buffer'],
            }),
          ],
        }
      }
    });
    

    或者如果你使用 embroider,你可以这样配置 webpack:

    // ember-cli-build.js
    
    const { Webpack } = require('@embroider/webpack');
    return require('@embroider/compat').compatBuild(app, Webpack, {
      packagerOptions: {
        webpackConfig: {
         plugins: [
            new webpack.ProvidePlugin({
              Buffer: ['buffer', 'Buffer'],
            }),
          ],
        }
      }
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-06-05
      • 2022-07-03
      • 2020-10-14
      • 1970-01-01
      • 1970-01-01
      • 2021-11-02
      相关资源
      最近更新 更多