I ran into a similar issue with Storybook. I found a clue by researching a similar error in a Gatsby app:
I was able to fix this by adding gatsby-node.js at the root of my project and the following rule on the webpack:
exports.onCreateWebpackConfig = ({ actions }) => {
actions.setWebpackConfig({
module: {
rules: [
{
test: /\.mjs$/,
include: /node_modules/,
type: 'javascript/auto',
},
],
},
})
}
Storybook uses a slightly different format for its configuration, so I had to add this to .storybook/main.js:
module.exports = {
...
webpackFinal: async (config, { configType }) => {
// Resolve error when webpack-ing storybook:
// Can't import the named export 'Children' from non EcmaScript module (only
// default export is available)
config.module.rules.push({
test: /\.mjs$/,
include: /node_modules/,
type: "javascript/auto",
});
return config;
}
}
I think you get the idea — add the above rule to webpack config, so that it treats *.mjs files correctly