It should work correctly with Webpack 5.9.0. Maybe transpiled lib should preserve the file extension in order to not break with webpack.
We are now trying to migrate our projects to Webpack 5 and we have experienced the following kind of errors:
ERROR in ./node_modules/react-children-utilities/react-children-utilities.js 10:0-38
Module not found: Error: Can't resolve './lib/onlyText' in '/.../.../.../.../botonic-examples/blank/node_modules/react-children-utilities'
Did you mean 'onlyText.js'?
BREAKING CHANGE: The request './lib/onlyText' failed to resolve only because it was resolved as fully specified
(probably because the origin is a '*.mjs' file or a '*.js' file where the package.json contains '"type": "module"').
The extension in the request is mandatory for it to be fully specified.
Add the extension to the request.
const babelLoaderConfig = {
exclude: /node_modules[\/\\](?!(@botonic)[\/\\])/,
use: {
loader: 'babel-loader',
options: {
cacheDirectory: true,
presets: ['@babel/preset-env', '@babel/react'],
plugins: [
'@babel/plugin-proposal-object-rest-spread',
'@babel/plugin-proposal-class-properties',
'babel-plugin-add-module-exports',
'@babel/plugin-transform-runtime',
],
},
},
}
If not fully necessary, do not specify type module in package.json. Otherwise, publish lib
with it's corresponding extensions.
Related issues (solutions proposed didn't work for me): graphql/graphql-js#2721
import { Children, isValidElement } from 'react';
import hasChildren from './hasChildren';
import { Children, isValidElement } from 'react';
import hasChildren from './hasChildren.js';