Description
Hi @fernandopasik, thanks for your project, it's pretty useful. We are using your code in order to traverse React trees in runtime and do some stuff to adapt dynamically how a chat must be shown depending on a messaging provider (Facebook, Whatsapp, ...).
Expected behavior
It should work correctly with Webpack 5.9.0. Maybe transpiled lib should preserve the file extension in order to not break with webpack.
Current behavior
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.
Steps to reproduce
- Init a project with Webpack 5.9.0.
- Configure babel (for example):
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',
],
},
},
}
- Try to compile the project with webpack.
Device information
- OS: MacOs
- Version: Node v12.20.0
Possible solution
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
In fact, changing manually the following code inside node_modules
fixed the issue:
import { Children, isValidElement } from 'react';
import hasChildren from './hasChildren';
to
import { Children, isValidElement } from 'react';
import hasChildren from './hasChildren.js';