I’m encountering an issue when trying to use the @wordpress/dataviews module in a Sage 10 theme with Bedrock. When I import DataViews
from @wordpress/dataviews
in my app.js
file, the entire JavaScript application stops working. There are no error messages in the browser console or in the PHP error log, making it difficult to diagnose.
Steps
- Install package
npm install @wordpress/dataviews --save
- Import the
DataViews
module inapp.js
with:
import domReady from '@roots/sage/client/dom-ready';
import { DataViews } from '@wordpress/dataviews';
console.log('DataViews', DataViews);
/**
* Application entrypoint
*/
domReady(async () => {
console.log('Hello world!');
});
/**
* @see {@link https://webpack.js.org/api/hot-module-replacement/}
*/
if (import.meta.webpackHot) import.meta.webpackHot.accept(console.error);
- Run the build process and load the page where this script is included. Nothing will be logged
- Comment out the import and first console.log:
...
// import { DataViews } from '@wordpress/dataviews';
// console.log('DataViews', DataViews);
...
- Run build again and
Hello world!
gets logged.
Questions:
- Has anyone else experienced this issue when using
@wordpress/dataviews
with Sage? - Are there any additional configurations or changes needed for Bud or Sage bundling settings to get this working?
- What are the best practices for debugging issues like this where the import of a module causes the script to silently fail without any errors in the console or logs? Are there specific tools or techniques within Sage, Webpack, or WordPress development that could help identify the root cause?