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

Scripts: "No entry files discovered in the "src" folder" with entry context in webpack.config.js #38739

Closed
ocean90 opened this issue Feb 11, 2022 · 5 comments · Fixed by #38737
Assignees
Labels
[Status] In Progress Tracking issues with work in progress [Tool] WP Scripts /packages/scripts [Type] Bug An existing feature does not function as intended

Comments

@ocean90
Copy link
Member

ocean90 commented Feb 11, 2022

Description

With 21.0.0 of @wordpress/scripts its no longer possible to use the entry context in webpack.config.js because the default config now uses an exit() call in

log(
chalk.bold.red( 'No entry files discovered in the "src" folder.' )
);
exit( 1 );

That's quite unfortunate and IMO not necessary. The exit should either be removed or first checked if an entry setting is set in webpack.config.js.

Step-by-step reproduction instructions

  1. Create a custom project with @wordpress/scripts
  2. Create a webpack.config.js with a custom entry setting
  3. Run wp-scripts start

Screenshots, screen recording, code snippet

Example of a webpack config:

const path = require( 'path' );
const defaultConfig = require( './node_modules/@wordpress/scripts/config/webpack.config' );

module.exports = {
	// https://github.com/WordPress/gutenberg/blob/master/packages/scripts/config/webpack.config.js
	...defaultConfig,

	// https://webpack.js.org/configuration/entry-context/#context
	context: path.resolve( __dirname, 'assets/js/src' ),

	// https://webpack.js.org/configuration/entry-context/#entry
	entry: {
		blocks: './blocks.js', // Entry for multiple block imports.
	},

	// https://webpack.js.org/configuration/output/
	output: {
		...defaultConfig.output,
		path: path.resolve( __dirname, 'assets/js/dist' ),
		filename: '[name].js',
	},
};

Environment info

No response

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

@gziolo
Copy link
Member

gziolo commented Feb 11, 2022

I have a fix ready for review and testing: #38737.

@gziolo gziolo added the [Status] In Progress Tracking issues with work in progress label Feb 11, 2022
@gziolo gziolo self-assigned this Feb 11, 2022
@gziolo
Copy link
Member

gziolo commented Feb 11, 2022

@wordpress/scripts@21.0.1 is available with the fix.

@shivapoudel
Copy link
Contributor

shivapoudel commented Feb 14, 2022

@gziolo @ocean90 We do have src folder for PHP codes how can I get rid of this message. Still persisting in my environment with version 21.0.1

image

Why is getWebpackEntryPoints called if I extend the config like this with extending entry:

/**
 * External dependencies
 */
const path = require( 'path' );
const RtlCssPlugin = require( 'rtlcss-webpack-plugin' );

/**
 * WordPress dependencies
 */
const defaultConfig = require( '@wordpress/scripts/config/webpack.config' );

module.exports = {
	...defaultConfig,
	context: path.resolve( __dirname, 'client' ),
	entry: {
		index: './index.js',
	},
	output: {
		...defaultConfig.output,
		chunkFilename: 'chunks/[name].js',
	},
	resolve: {
		...defaultConfig.resolve,
		modules: [ path.join( __dirname, 'client' ), 'node_modules' ],
	},
	plugins: [
		...defaultConfig.plugins,
		new RtlCssPlugin( {
			filename: '[name]-rtl.css',
		} ),
	],
};

@shivapoudel
Copy link
Contributor

@gziolo Can you help me with the ^ comment? Thanks in advance!

@gziolo
Copy link
Member

gziolo commented Mar 28, 2022

@gziolo Can you help me with the ^ comment? Thanks in advance!

Yes, it still need a fix for your use case. I commented about a potential solution here: #39618 (comment). It’s only a message, your code should work correctly.

thongtr-dev added a commit to thongtr-dev/related-post-slider-block that referenced this issue Nov 3, 2022
The @wordpress/scripts package above version 21.0.2 doesn't extend the default config entries in webpack config file. Instead, the custom entry points will replace all of the default entries. The issue is described here WordPress/gutenberg#38739 .

It is appeared that the issue is marked as closed but the problem still persists. This commit downgrades the @wordpress/scripts back to 21.0.2 to allow custom entry build points.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Status] In Progress Tracking issues with work in progress [Tool] WP Scripts /packages/scripts [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants