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/node:webpack Cannot export multiple configurations #9453

Closed
amri04 opened this issue Mar 22, 2022 · 3 comments
Closed

@nx/node:webpack Cannot export multiple configurations #9453

amri04 opened this issue Mar 22, 2022 · 3 comments
Labels
outdated scope: node Issues related to Node, Express, NestJS support for Nx stale type: bug

Comments

@amri04
Copy link

amri04 commented Mar 22, 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/node:webpack",
       "outputs": ["{options.outputPath}"],
       "defaultConfiguration": "production",
       "options": {
        ...
         "webpackConfig": "apps/app-name/webpack.config.ts"
       },
  1. define custom webpack configuration.
  // ...
  module.exports = (config: Configuration, context: any) => {
     const firstConfig= {
         // ...
         output: {
             path: 'path',
             libraryTarget: 'amd',
             //...
         },
         // ...
     }
     const secondConfig= {
         // ...
         output: {
             path: 'other/path',
             libraryTarget: 'commonjs',
             //...
         },
         // ...
     }
     return [firstConfig,secondConfig];
  }
  // ...
  1. Run nx run 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

   Node : 14.18.0
   OS   : win32 x64
   npm  : 8.5.3

   nx : 13.8.6
   @nrwl/angular : 13.8.6
   @nrwl/cli : 13.8.6
   @nrwl/cypress : 13.8.6
   @nrwl/detox : undefined
   @nrwl/devkit : 13.8.6
   @nrwl/eslint-plugin-nx : 13.8.6
   @nrwl/express : undefined
   @nrwl/jest : 13.8.6
   @nrwl/js : 13.8.6
   @nrwl/linter : 13.8.6
   @nrwl/nest : 13.8.6
   @nrwl/next : undefined
   @nrwl/node : 13.8.6
   @nrwl/nx-cloud : undefined
   @nrwl/react : undefined
   @nrwl/react-native : undefined
   @nrwl/schematics : undefined
   @nrwl/storybook : 13.8.6
   @nrwl/tao : 13.8.6
   @nrwl/web : undefined
   @nrwl/workspace : 13.8.6
   typescript : 4.4.4
   rxjs : 7.5.5

Remark

The issue is very similar to the one that was resolved by @sidmonta on the web executor (#9188 , #9186)

@AgentEnder AgentEnder added the scope: node Issues related to Node, Express, NestJS support for Nx label Mar 22, 2022
@sidmonta
Copy link
Contributor

Hi @amri04, thanks for the tip. I investigated a bit and noticed that the implementation is a bit different from the web executor

const config = options.webpackConfig.reduce((currentConfig, plugin) => {

I think I can do something about it without breaking backward compatibility.

Between today and tomorrow, I should be able to work on it a bit. If you'd like to help with testing, you can try my fork: https://github.com/sidmonta/nx

Thanks

sidmonta added a commit to sidmonta/nx that referenced this issue Mar 22, 2022
…file

When use a custom configuration file for node webpack build target.
allow running webpack with
multiple configuration options

ISSUES CLOSED: nrwl#9453
sidmonta added a commit to sidmonta/nx that referenced this issue Apr 4, 2022
…file

When use a custom configuration file for node webpack build target.
allow running webpack with
multiple configuration options

ISSUES CLOSED: nrwl#9453
@github-actions
Copy link

This issue has been automatically marked as stale because it hasn't had any recent activity. It will be closed in 14 days if no further activity occurs.
If we missed this issue please reply to keep it active.
Thanks for being a part of the Nx community! 🙏

@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 21, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
outdated scope: node Issues related to Node, Express, NestJS support for Nx stale type: bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants