-
Notifications
You must be signed in to change notification settings - Fork 4.8k
warning package is not compatible with webpack 5 #44950
Copy link
Copy link
Closed
Labels
[Package] Warning/packages/warning/packages/warning[Status] In ProgressTracking issues with work in progressTracking issues with work in progress[Type] BugAn existing feature does not function as intendedAn existing feature does not function as intended[Type] Build ToolingIssues or PRs related to build toolingIssues or PRs related to build tooling
Description
Description
@wordpress/warning and its babel-plugin rely on process.env. So for env == 'production' it's supposed not to show the warning.
The problem is webpack 5 removed process variable completely:
- https://webpack.js.org/blog/2020-10-10-webpack-5-release/#changes-to-the-structure
Automatic polyfills for native Node.js modules were removed
node.processremoved - https://webpack.js.org/migrate/5/#run-a-single-build-and-follow-advice
webpack 5 does no longer include a polyfill for this Node.js variable. Avoid using it in the frontend code.
process.envis Node.js specific and should be avoided in frontend code.
So, the typeof process !== 'undefined' && process.env !=== 'production' is always false, which prevents warning to be called for any kind of environment.
Step-by-step reproduction instructions
Follow the package's README
- Put
@wordpress/warning/babel-plugininto your babel config or use@wordpress/babel-preset-default, which already includes the babel plugin. -
import warning from '@wordpress/warning'; warning( 'You should see me' );
- Build your bundle with webpack 5
Screenshots, screen recording, code snippet
No response
Environment info
"@wordpress/warning": "2.19.0",
"webpack": "^5.74.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
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
[Package] Warning/packages/warning/packages/warning[Status] In ProgressTracking issues with work in progressTracking issues with work in progress[Type] BugAn existing feature does not function as intendedAn existing feature does not function as intended[Type] Build ToolingIssues or PRs related to build toolingIssues or PRs related to build tooling
Type
Fields
Give feedbackNo fields configured for issues without a type.