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

@nrwl/rollup: Build fails with multiple build configs via array syntax in rollup.config.js #16567

Closed
thomassimko opened this issue Apr 26, 2023 · 3 comments · Fixed by #22703
Closed
Assignees
Labels
outdated scope: bundlers Issues related to webpack, rollup type: bug

Comments

@thomassimko
Copy link

thomassimko commented Apr 26, 2023

Current Behavior

When specifying the rollup.config.js option in the project.json file, if that rollup config returns an array of configurations, the build fails with the error message:

Unknown input options: 0, 1. Allowed options: acorn, acornInjectPlugins, cache, context, experimentalCacheExpiry, external, inlineDynamicImports, input, makeAbsoluteExternalsRelative, manualChunks, maxParallelFileOps, maxParallelFileReads, moduleContext, onwarn, perf, plugins, preserveEntrySignatures, preserveModules, preserveSymlinks, shimMissingExports, strictDeprecations, treeshake, watch Error during bundle: Error: You must supply options.input to rollup

the custom rollup config we are using is:

const nrwlConfig = require('@nrwl/react/plugins/bundle-rollup');
const postcss = require('rollup-plugin-postcss');
const autoprefixer = require('autoprefixer');
const md5 = require('md5');

module.exports = (config) => {
  const nxConfig = nrwlConfig(config);
  const configWithoutPostCSS = nxConfig.plugins.filter((names) => names.name !== 'postcss');
  return [
    {
      ...nxConfig,
      plugins: [
        postcss({
          inject: true,
          extract: true,
          modules: {
            generateScopedName: (name, filename, css) => name + '_' + md5(css),
          },
          plugins: [autoprefixer],
        }),
        ...configWithoutPostCSS,
      ],
    },
    {
      ...nxConfig,
      output: {
        ...nxConfig.output,
        name: `fat-${nxConfig.output.name}`,
      },
      plugins: [
        postcss({
          inject: true,
          extract: false,
          modules: {
            generateScopedName: (name, filename, css) => name + '_' + md5(css),
          },
          plugins: [autoprefixer],
        }),
        ...configWithoutPostCSS,
      ],
    },
  ];
};

Expected Behavior

Rollup supports multiple configurations in a rollup.config.js file by returning an array of configurations. For example see this example configuration from the rollup docs: https://rollupjs.org/configuration-options/#watch. I would expect multiple output files to be generated.

GitHub Repo

https://github.com/thomassimko/nx-rollup-multi-config

Steps to Reproduce

  1. Run npm install
  2. Run npm build and it fails. I have provided 2 rollup configs: one with the array configuration (rollup.config.js) and one without (rollup-working.config.js).

Nx Report

>  NX   Report complete - copy this into the issue template

   Node : 16.16.0
   OS   : darwin x64
   yarn : 1.22.19
   
   nx                      : 15.9.2
   lerna                   : 6.5.1
   @nrwl/js                : 15.9.2
   @nrwl/jest              : 15.9.2
   @nrwl/linter            : 15.9.2
   @nrwl/workspace         : 15.9.2
   @nrwl/cli               : 15.9.2
   @nrwl/cypress           : 15.9.2
   @nrwl/eslint-plugin-nx  : 15.9.2
   @nrwl/react             : 15.9.2
   @nrwl/rollup            : 15.9.2
   @nrwl/storybook         : 15.9.2
   @nrwl/tao               : 15.9.2
   @nrwl/vite              : 15.9.2
   @nrwl/web               : 15.9.2
   @nrwl/webpack           : 15.9.2
   typescript              : 5.0.2
   ---------------------------------------
   Community plugins:
   nx-stylelint : 14.0.2

Failure Logs

Bundling react-button...
Unknown input options: 0, 1. Allowed options: acorn, acornInjectPlugins, cache, context, experimentalCacheExpiry, external, inlineDynamicImports, input, makeAbsoluteExternalsRelative, manualChunks, maxParallelFileOps, maxParallelFileReads, moduleContext, onwarn, perf, plugins, preserveEntrySignatures, preserveModules, preserveSymlinks, shimMissingExports, strictDeprecations, treeshake, watch
Error during bundle: Error: You must supply options.input to rollup
Unknown input options: 0, 1. Allowed options: acorn, acornInjectPlugins, cache, context, experimentalCacheExpiry, external, inlineDynamicImports, input, makeAbsoluteExternalsRelative, manualChunks, maxParallelFileOps, maxParallelFileReads, moduleContext, onwarn, perf, plugins, preserveEntrySignatures, preserveModules, preserveSymlinks, shimMissingExports, strictDeprecations, treeshake, watch
Error during bundle: Error: You must supply options.input to rollup
Bundle failed: react-button

Additional Information

No response

@AgentEnder AgentEnder added the scope: bundlers Issues related to webpack, rollup label Apr 26, 2023
@jclarkcisco
Copy link

Any updates on this?

@ept-Ayush
Copy link

ept-Ayush commented Nov 20, 2023

Are u able to fix that @thomassimko @AgentEnder @jaysoo ?

I found out the issue is when passing multiple rollup config

options.rollupConfig.reduce((currentConfig, plugin) => {
            return require(plugin)(currentConfig, options);
        }, rollupConfig);

This is creating a nested array which is causing the issue at

    return (0, rxjs_1.from)(rollupOptions)
            .pipe((0, operators_1.concatMap)((opts) => (0, run_rollup_1.runRollup)(opts).pipe((0, operators_1.catchError)((e) => {
            devkit_1.logger.error(`Error during bundle: ${e}`);
            return (0, rxjs_1.of)({ success: false });
        }))), (0, operators_1.scan)((acc, result) => {
            if (!acc.success)
                return acc;
            return result;
        }, { success: true, outfile }), (0, operators_1.last)(), (0, operators_1.tap)({
            next: (result) => {
                if (result.success) {
                    const end = process.hrtime.bigint();
                    const duration = `${(Number(end - start) / 1000000000).toFixed(2)}s`;
                    (0, update_package_json_1.updatePackageJson)(options, packageJson);
                    devkit_1.logger.info(`⚡ Done in ${duration}`);
                }
                else {
                    devkit_1.logger.error(`Bundle failed: ${context.projectName}`);
                }
            },
        }))
            .toPromise();

Copy link

github-actions bot commented May 6, 2024

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 May 6, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
outdated scope: bundlers Issues related to webpack, rollup type: bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants