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

Plugin array is undefined in custom webpack.config.js. #29504

Open
brayanL opened this issue Jan 3, 2025 · 0 comments
Open

Plugin array is undefined in custom webpack.config.js. #29504

brayanL opened this issue Jan 3, 2025 · 0 comments

Comments

@brayanL
Copy link

brayanL commented Jan 3, 2025

According to the following instructions to configure environment variables in an Angular project, we need to provide a custom webpack configuration, but in my case the plugins array in config object is undefined, for that reason NX project cannot be executed. Please update your documentation to add the following initialization:
config.plugins = config.plugins || [];

The complete code will be:


function getClientEnvironment() {
  const envVars = {};
  for (const key in process.env) {
    envVars[key] = process.env[key];
  }

  return {
    'process.env': JSON.stringify(envVars),
  };
}

module.exports = (config, options, context) => {
  // Overwrite the mode set by Angular if the NODE_ENV is set
  config.mode = process.env.NODE_ENV || config.mode;
  config.plugins = config.plugins || [];
  config.plugins.push(new webpack.DefinePlugin(getClientEnvironment()));
  return config;
};

My packages are:

  • "@nx/angular": "20.2.2"
  • "nx": "20.2.2"
  • "webpack-cli": "^5.1.4"

https://nx.dev/recipes/angular/use-environment-variables-in-angular#use-a-custom-webpack-configuration-to-support-environment-variables

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

1 participant