You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
It seems like wp-scripts build includes devDependencies #79205
I'm not 100% sure, but it seems like the wp-scripts build script includes my devDependencies in the output. In any case, when I move packages back and forth between devDependencies and dependencies, the output files are exactly the same after running the build script.
Step-by-step reproduction instructions
add something to the devDependencies array in package.json.
Use that thing in a block
use wp-scripts build to build the block
move the thing from devDependencies to dependencies
You will find that the output is the same size.
Expected
I would expect that the devDependency would not be included in the build output, causing the bundle to be smaller.
Screenshots, screen recording, code snippet
No response
Environment info
wordpress 7.0
@wordpress/scripts 32.4.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
Please confirm which theme type you used for testing.
I investigated the behavior using a fresh block created with @wordpress/create-block and tested with @wordpress/scripts 32.4.1.
What I tested
Installed lodash as a devDependency.
Imported and used it in the block's editor code.
Ran wp-scripts build and recorded the generated bundle size and asset manifest.
Moved lodash from devDependencies to dependencies.
Reinstalled dependencies and rebuilt the block.
Compared the generated output.
Results
In both cases:
The generated index.js bundle size remained the same.
The generated index.asset.php remained the same.
lodash was listed as a dependency in the asset file.
The bundle referenced window.lodash rather than bundling the library itself.
While investigating further, I found that the dependency extraction plugin appears to determine externals based on the imported module request (e.g. lodash → lodash) and does not appear to inspect whether a package is declared under dependencies or devDependencies.
At this point, I can reproduce the reported behavior, but I'm not yet sure whether this is an implementation bug or an expectation mismatch. Could you clarify what behavior you expect when a package is imported in runtime block code but is listed under devDependencies? Should such imports be excluded from dependency extraction and build output?
The bundle referenced window.lodash rather than bundling the library itself.
It might be cleaner to test with a different package (not lodash or wordpress/scripts which don't actually get packaged in favor of the globally available version).
My Expectations:
I would expect that if I have a package listed in dependency, when I run wp-scripts build, that this package would be included, since the build script is considered the production build.
If I have a package listed in devDependency, when I run wp-scripts build, this package would not be included. If my production built script tried to access functionality which was included in a package included in devDeps, it would fail. because the functionality doesn't exist in the production build. That would be on me as the developer to fix that problem.
I ran an additional test using dayjs (a package that is not externalized by the dependency extraction plugin) to rule out the special handling of packages such as lodash.
Test setup
Installed dayjs as a devDependency.
Imported and used it in block code.
Ran wp-scripts build and recorded the generated output.
Moved dayjs from devDependencies to dependencies.
Reinstalled dependencies and rebuilt.
Compared the generated output.
Results
The generated output was identical in both cases:
index.js: 8629 bytes
Build directory size: 48 KB
This matched the behavior I previously observed with lodash.
From the implementation side, the build process appears to be driven by the webpack module graph (i.e. what is imported by the application code). During my investigation I wasn't able to find any logic in @wordpress/scripts or the dependency extraction plugin that changes bundling behavior based on whether a package is declared under dependencies or devDependencies.
Given your expectations, I'd be interested in hearing whether maintainers consider this current behavior intentional, or whether wp-scripts build is expected to treat imported packages differently based on their dependency classification in package.json. If there are any prior discussions, design decisions, or documentation around this behavior, I'd be happy to review them.
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.
This is still an issue. I'd like to hear whether this is expected or something that needs to be fixed. If it's expected, it wouldn't be a bad idea to add this information to the docs.
devDependencies or dependencies is strictly a npm concern and not a bundling concern. So webpack or wp-scripts will bundle whatever is imported regardless of how the dependency is defined. This is the same behavior for any bundler. So I believe this is working as intended.
Activity
theritiktiwari commentedon Jun 17, 2026
Thanks @jakeparis for reporting this issue.
I investigated the behavior using a fresh block created with
@wordpress/create-blockand tested with@wordpress/scripts32.4.1.What I tested
lodashas adevDependency.wp-scripts buildand recorded the generated bundle size and asset manifest.lodashfromdevDependenciestodependencies.Results
In both cases:
index.jsbundle size remained the same.index.asset.phpremained the same.lodashwas listed as a dependency in the asset file.window.lodashrather than bundling the library itself.While investigating further, I found that the dependency extraction plugin appears to determine externals based on the imported module request (e.g.
lodash→lodash) and does not appear to inspect whether a package is declared underdependenciesordevDependencies.At this point, I can reproduce the reported behavior, but I'm not yet sure whether this is an implementation bug or an expectation mismatch. Could you clarify what behavior you expect when a package is imported in runtime block code but is listed under
devDependencies? Should such imports be excluded from dependency extraction and build output?jakeparis commentedon Jun 17, 2026
It might be cleaner to test with a different package (not lodash or wordpress/scripts which don't actually get packaged in favor of the globally available version).
My Expectations:
dependency, when I runwp-scripts build, that this package would be included, since thebuildscript is considered the production build.devDependency, when I runwp-scripts build, this package would not be included. If my production built script tried to access functionality which was included in a package included indevDeps, it would fail. because the functionality doesn't exist in the production build. That would be on me as the developer to fix that problem.theritiktiwari commentedon Jun 20, 2026
Thanks for clarifying your expectations.
I ran an additional test using
dayjs(a package that is not externalized by the dependency extraction plugin) to rule out the special handling of packages such aslodash.Test setup
dayjsas adevDependency.wp-scripts buildand recorded the generated output.dayjsfromdevDependenciestodependencies.Results
The generated output was identical in both cases:
index.js: 8629 bytesThis matched the behavior I previously observed with
lodash.From the implementation side, the build process appears to be driven by the webpack module graph (i.e. what is imported by the application code). During my investigation I wasn't able to find any logic in
@wordpress/scriptsor the dependency extraction plugin that changes bundling behavior based on whether a package is declared underdependenciesordevDependencies.Given your expectations, I'd be interested in hearing whether maintainers consider this current behavior intentional, or whether
wp-scripts buildis expected to treat imported packages differently based on their dependency classification inpackage.json. If there are any prior discussions, design decisions, or documentation around this behavior, I'd be happy to review them.github-actions commentedon Jul 21, 2026
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.
jakeparis commentedon Jul 21, 2026
This is still an issue. I'd like to hear whether this is expected or something that needs to be fixed. If it's expected, it wouldn't be a bad idea to add this information to the docs.
youknowriad commentedon Jul 22, 2026
devDependencies or dependencies is strictly a npm concern and not a bundling concern. So webpack or wp-scripts will bundle whatever is imported regardless of how the dependency is defined. This is the same behavior for any bundler. So I believe this is working as intended.