Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

process and Buffer not defined when using Webpack 5 #1338

Closed
federicochiesa opened this issue Oct 12, 2021 · 4 comments
Closed

process and Buffer not defined when using Webpack 5 #1338

federicochiesa opened this issue Oct 12, 2021 · 4 comments

Comments

@federicochiesa
Copy link

As the title says, when I try to use MQTT.js with Webpack 5 I get these errors and I can't run my code.

I installed Buffer using npm install buffer but that didn't change a thing.

@ErlendAHall
Copy link

This happens because Webpack 5 no longer automatically bundles core node modules, or they might be browser polyfills (correct me if Im wrong).

  • First off, install buffer and process.

  • Then, if you have access to the webpack config, add these under resolve.fallback
    image
    Basically, you tell webpack if it encounters some unresolved modules amongst your dependencies, then here is a list of possible fallbacks.

  • Finally, we need to make sure the browser won't reference globalThis.process or globalThis.Buffer once you execute in browser. These modules comes from the Node namespace.

  • webpack.ProvidePlugin can be used to create an"alias" so that webpack will pop into node_modules and include buffer and process into the bundle.

image

@federicochiesa
Copy link
Author

Thanks! That fixed it.

@Pavanct
Copy link

Pavanct commented Feb 17, 2022

Any thoughts on how to fix this in React?

@vkiranmaniya
Copy link

Any thoughts on how to fix this in React?

Are you using CRA?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants