-
-
Notifications
You must be signed in to change notification settings - Fork 42
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
[bug] dynamic imports doesn't work with extracted WordPress dependencies #2545
Comments
How exactly are you doing this? Are you using the bundle function from Acorn? |
We use the bedrock and sage theme. add_action('wp_enqueue_scripts', function () {
bundle('category')->enqueue();
}, 100); The problem occurs in development mode. The development mode is launched with a |
I haven't looked at this super closely yet but at first glance: you can't dynamically import WordPress dependencies as they are included via window variables. As in, your source: import { __ } from '@wordpress/i18n' compiles to something like: const __ = wp.i18n.__
I've never tried to dynamically import WP dependencies because of this reason and while it would be nice if it worked, it seems that it doesn't. This might be an improvement that we can make to As a workaround I would add any import statements to the entrypoint so that they are properly picked up on by the plugins. Example for an entrypoint called import '@wordpress/i18n' // flag external pkg
// ... your source |
Message to comment on stale issues. If none provided, will not mark issues stale |
Agreement
Describe the issue
If I dynamically import a module that includes import of WP dependencies, this module is loaded without WP dependencies.
Expected Behavior
The dependencies of the WP are dynamically loaded and initialize global variables before the main module is executed.
Actual Behavior
Wordpress dependencies are extracted but not dynamically loaded when the module is loaded.
Steps To Reproduce
version
6.20.0
Logs
No response
Configuration
No response
Relevant .budfiles
No response
The text was updated successfully, but these errors were encountered: