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

@nx/web:webpack Cannot use multiple configuration on custom config file option #9186

Closed
sidmonta opened this issue Mar 4, 2022 · 3 comments · Fixed by #9188
Closed

@nx/web:webpack Cannot use multiple configuration on custom config file option #9186

sidmonta opened this issue Mar 4, 2022 · 3 comments · Fixed by #9188
Labels
outdated scope: react Issues related to React support for Nx type: bug

Comments

@sidmonta
Copy link
Contributor

sidmonta commented Mar 4, 2022

Current Behavior

Assigning a custom webpack configuration file does not support the ability to use multiple configurations, as webpack allows.

Expected Behavior

Being able to define multiple configurations in my custom webpack.config.ts file to feed to webpack

Steps to Reproduce

  1. set a custom webpack config option in build target options on project.json.

      ...
      "targets": {
         "build": {
           "executor": "@nrwl/web:webpack",
           "outputs": ["{options.outputPath}"],
           "defaultConfiguration": "production",
           "options": {
            ...
             "webpackConfig": "apps/app-name/webpack.config.ts"
           },
           ...
    
  2. define custom webpack configuration

      // ...
      module.exports = (config: Configuration, context: any) => {
         const customConfig = {
             // ...
             output: {
                 path: 'other/path',
                 //...
             },
             // ...
         }
         return [merge(commonConfig, customConfig), config];
      }
      // ...
  3. Run yarn nx app-name:build

Failure Logs

Invalid configuration object. Webpack has been initialized using a configuration object that does not match the API schema.
 - configuration has an unknown property '0'. These properties are valid:
   object { amd?, bail?, cache?, context?, dependencies?, devServer?, devtool?, entry?, experiments?, externals?, externalsPresets?, externalsType?, ignoreWarnings?, infrastructureLogging?, loader?, mode?, module?, name?, node?, optimization?, output?, parallelism?, performance?, plugins?, profile?, recordsInputPath?, recordsOutputPath?, recordsPath?, resolve?, resolveLoader?, snapshot?, stats?, target?, watch?, watchOptions? }
   -> Options object as provided by the user.
   For typos: please correct them.
   For loader options: webpack >= v2.0.0 no longer allows custom properties in configuration.
     Loaders should be updated to allow passing options via loader options in module.rules.
     Until loaders are updated one can use the LoaderOptionsPlugin to pass these options to the loader:
     plugins: [
       new webpack.LoaderOptionsPlugin({
         // test: /\.xxx$/, // may apply this only for some modules
         options: {
           0: …
         }
       })
     ]

Environment

 >  NX   Report complete - copy this into the issue template

   Node : 17.4.0
   OS   : linux x64
   yarn : 1.22.17
   
   nx : 13.8.3
   @nrwl/angular : undefined
   @nrwl/cli : 13.8.3
   @nrwl/cypress : 13.8.3
   @nrwl/detox : undefined
   @nrwl/devkit : 13.8.3
   @nrwl/eslint-plugin-nx : 13.8.3
   @nrwl/express : undefined
   @nrwl/jest : 13.8.3
   @nrwl/js : 13.8.3
   @nrwl/linter : 13.8.3
   @nrwl/nest : undefined
   @nrwl/next : undefined
   @nrwl/node : 13.8.3
   @nrwl/nx-cloud : undefined
   @nrwl/react : 13.8.3
   @nrwl/react-native : undefined
   @nrwl/schematics : undefined
   @nrwl/storybook : 13.8.3
   @nrwl/tao : 13.8.3
   @nrwl/web : 13.8.3
   @nrwl/workspace : 13.8.3
   typescript : 4.5.5
   rxjs : 6.6.7
   ---------------------------------------
sidmonta added a commit to sidmonta/nx that referenced this issue Mar 4, 2022
…guration file

When use a custom configuration file for webpack build target allow to run webpack with
multiple
configuration options.
ISSUES CLOSED: nrwl#9186
@sidmonta
Copy link
Contributor Author

sidmonta commented Mar 4, 2022

I've created a basic example to show the error:

https://stackblitz.com/edit/github-rrik4f-u61kmx?file=apps/my-app/webpack.config.ts

@AgentEnder AgentEnder added the scope: react Issues related to React support for Nx label Mar 4, 2022
kirjai pushed a commit that referenced this issue Mar 10, 2022
…guration file (#9188)

When use a custom configuration file for webpack build target allow to run webpack with
multiple
configuration options.
ISSUES CLOSED: #9186
@amri04
Copy link

amri04 commented Mar 22, 2022

Hi @sidmonta , could the same be done for the node executor ?
I have exactly the same problem there.

@github-actions
Copy link

This issue has been closed for more than 30 days. If this issue is still occuring, please open a new issue with more recent context.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 22, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
outdated scope: react Issues related to React support for Nx type: bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants