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

wp-scripts: using --experimental-modules causes TypeError: config.plugins is not iterable when webpack.config.js is extending plugins. #60537

Closed
nextgenthemes opened this issue Apr 7, 2024 · 7 comments
Labels
[Package] Scripts /packages/scripts [Type] Help Request Help with setup, implementation, or "How do I?" questions.

Comments

@nextgenthemes
Copy link

Description

Reduced webpack.config.js. Works perfectly fine without --experimental-modules

const WebpackNotifierPlugin = require( 'webpack-notifier' );
const defaultConfig = require( '@wordpress/scripts/config/webpack.config' );

const config = defaultConfig;

config.plugins = [ ...config.plugins, new WebpackNotifierPlugin( { onlyOnError: true } ) ];

module.exports = config;

commandline:

wp-scripts build --experimental-modules --webpack-copy-php --webpack-src-dir=plugins/nextgenthemes-blocks/src --output-path=plugins/nextgenthemes-blocks/build

[webpack-cli] Failed to load '/u/websites/webpack.config.js' config
[webpack-cli] TypeError: config.plugins is not iterable
    at Object.<anonymous> (/u/websites/webpack.config.js:6:30)
    at Module._compile (node:internal/modules/cjs/loader:1368:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1426:10)
    at Module.load (node:internal/modules/cjs/loader:1205:32)
    at Module._load (node:internal/modules/cjs/loader:1021:12)
    at Module.require (node:internal/modules/cjs/loader:1230:19)
    at require (node:internal/modules/helpers:179:18)
    at WebpackCLI.tryRequireThenImport (/u/websites/node_modules/webpack-cli/lib/webpack-cli.js:223:30)
    at loadConfigByPath (/u/websites/node_modules/webpack-cli/lib/webpack-cli.js:1406:38)
    at WebpackCLI.loadConfig (/u/websites/node_modules/webpack-cli/lib/webpack-cli.js:1515:44)

Step-by-step reproduction instructions

  1. use webpack.config.js to extend plugins
  2. run wp-scripts

Screenshots, screen recording, code snippet

No response

Environment info

@wordpress/scripts@27.6.0

node -v
v21.7.2

npm -v
10.5.0

Please confirm that you have searched existing issues in the repo.

Yes

Please confirm that you have tested with all plugins deactivated except Gutenberg.

Yes

@nextgenthemes nextgenthemes added the [Type] Bug An existing feature does not function as intended label Apr 7, 2024
@nextgenthemes nextgenthemes changed the title Using --experimental-modules causes TypeError: config.plugins is not iterable when webpack.config.js is extending plugins. Apr 7, 2024
@t-hamano t-hamano added [Package] Scripts /packages/scripts Needs Testing Needs further testing to be confirmed. labels Apr 7, 2024
Copy link

github-actions bot commented May 8, 2024

Hi,
This issue has gone 30 days without any activity. This means it is time for a check-in to make sure it is still relevant. If you are still experiencing this issue with the latest versions, you can help the project by responding to confirm the problem and by providing any updated reproduction steps.
Thanks for helping out.

@github-actions github-actions bot added the [Status] Stale Gives the original author opportunity to update before closing. Can be reopened as needed. label May 8, 2024
@nextgenthemes
Copy link
Author

yes

@github-actions github-actions bot removed the [Status] Stale Gives the original author opportunity to update before closing. Can be reopened as needed. label May 9, 2024
Copy link

github-actions bot commented Jun 8, 2024

Hi,
This issue has gone 30 days without any activity. This means it is time for a check-in to make sure it is still relevant. If you are still experiencing this issue with the latest versions, you can help the project by responding to confirm the problem and by providing any updated reproduction steps.
Thanks for helping out.

@github-actions github-actions bot added the [Status] Stale Gives the original author opportunity to update before closing. Can be reopened as needed. label Jun 8, 2024
@nextgenthemes
Copy link
Author

yes

@github-actions github-actions bot removed the [Status] Stale Gives the original author opportunity to update before closing. Can be reopened as needed. label Jun 9, 2024
@TheAggressive
Copy link

Also recieving this error. Any help or did you resolve this?

@t-hamano
Copy link
Contributor

I'm not sure of the exact cause, but it seems that when the --experimental-modules flag is enabled, this problem occurs because the defaultConfig is an object, not an array.

Therefore, I overwrote the settings for each element of the array as shown below, and the error no longer appeared:

const WebpackNotifierPlugin = require( 'webpack-notifier' );
const defaultConfig = require( '@wordpress/scripts/config/webpack.config' );

const config = defaultConfig.map( ( config ) => {
	return {
		...config,
		plugins: [ ...config.plugins, new WebpackNotifierPlugin( { onlyOnError: true } ) ],
	};
});

module.exports = config;

I hope this helps.

@t-hamano t-hamano added [Type] Help Request Help with setup, implementation, or "How do I?" questions. and removed Needs Testing Needs further testing to be confirmed. [Type] Bug An existing feature does not function as intended labels Jul 27, 2024
@gziolo
Copy link
Member

gziolo commented Jul 27, 2024

Yes, @t-hamano is correct. Currently there need to be two configs to support ES Modules. That’s why it’s behind the experimental flag and subject to change in the future.

@gziolo gziolo closed this as completed Jul 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Package] Scripts /packages/scripts [Type] Help Request Help with setup, implementation, or "How do I?" questions.
4 participants