【问题标题】:can not build react project due to webpack由于 webpack 无法构建反应项目
【发布时间】:2022-07-30 04:16:45
【问题描述】:

我遇到了一个烦人的问题。我正在尝试在其他事情上使用 web3 构建一个项目,但我遇到了一些我无法解决的编译错误:

Compiled with problems: X

ERROR in ../node_modules/cipher-base/index.js 3:16-43

Module not found: Error: Can't resolve 'stream' in 'C:\CAS\node_modules\cipher-base'

BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.

If you want to include a polyfill, you need to:
    - add a fallback 'resolve.fallback: { "stream": require.resolve("stream-browserify") }'
    - install 'stream-browserify'
If you don't want to include a polyfill, you can use an empty module like this:
    resolve.fallback: { "stream": false }

我尝试了很多东西,但无法成功。 有人可以帮忙吗?

【问题讨论】:

标签: javascript


【解决方案1】:

我成功了

在网站根目录添加:webpack.config

包含:

    module.exports = {
resolve: {
    fallback: {
        assert: require.resolve('assert'),
        crypto: require.resolve('crypto-browserify'),
        http: require.resolve('stream-http'),
        https: require.resolve('https-browserify'),
        os: require.resolve('os-browserify/browser'),
        stream: require.resolve('stream-browserify'),
    },
},
// Webpack 5 is enabled by default
// You can still use webpack 4 while upgrading to the latest version of Next.js by adding the "webpack5: false" flag
webpack5: false,

};

【讨论】:

    猜你喜欢
    • 2020-09-04
    • 1970-01-01
    • 2021-09-25
    • 2018-05-12
    • 1970-01-01
    • 2014-06-25
    • 1970-01-01
    • 2021-04-10
    • 2015-04-17
    相关资源
    最近更新 更多