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

rspack "process not defined" error when trying to use process.env #361

Open
Nick-Lucas opened this issue Dec 10, 2023 · 2 comments
Open

Comments

@Nick-Lucas
Copy link

Currently the rspack plugin seems not to support process out of the box, so the normal configuration approach of .env files in Nx does not work.

@141616
Copy link

141616 commented Feb 26, 2024

Currently the rspack plugin seems not to support process out of the box, so the normal configuration approach of .env files in Nx does not work.

https://www.rspack.dev/guide/language-support.html#node-polyfills

@phal0r
Copy link

phal0r commented Feb 27, 2024

I stumled upon the same problem. The env files are read properly, but the define plugin is missing.

My workaround (the code must be added in the rspack.config file):

const defines = {}
  Object.keys(process.env).forEach(function(key) {
    if(key.startsWith("NX_")) {
      defines['process.env.' + key] = JSON.stringify(process.env[key])
    }
  });
  config.plugins.push(new rspack.DefinePlugin(defines))

This will replace all process.env.NX_* variables in the frontend code.

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

3 participants