I'm submitting a bug report
Webpack Version:
4.19.1
Babel Core Version:
7.1.0
Babel Loader Version:
8.0.2
Please tell us about your environment:
Windows 10
Current behavior:
Files from a subdirectory that has a package.json file are not transpiled.
Minimal example: https://github.com/metalex9/babel-loader-issue
In ^this example, the code from inside fake-module/index.js is not transpiled when running webpack (with npm start). However, if you remove or rename fake-module/package.json and rerun webpack, the code from fake-module/index.js will be transpiled as expected. Also note that this code from the entry point is transpiled like I'd expect.
To verify that fake-module/index.js is passed to babel-loader, I used inspect-loader to output if the file was sent through the loader chain.
I also tried copying the .babelrc file inside fake-module which did not help.
I'm not positive the problem actually resides in babel-loader; let me know if that's not the case!
Expected/desired behavior:
All files passed to babel-loader should be transpiled.
Thank you!
This is expected behavior now in Babel 7. I'd recommend taking a look the docs for .babelrc behavior here: https://babeljs.io/docs/en/config-files#file-relative-configuration
The easiest fix for you would be to convert your .babelrc to a babel.config.js exporting the config.
Ah, I wondered if that was the case but couldn't find anything. Thank you so much!
@metalex9 Hey would you be willing to provide an example of how you fixed it?
@shkfnly I did just what was suggested above and changed my .babelrc file to a babel.config.js
.babelrc (removed):
{
"presets": ["@babel/env", "@babel/react"],
"plugins": ["@babel/syntax-dynamic-import"]
}
babel.config.js (added):
module.exports = {
presets: ['@babel/env', '@babel/react'],
plugins: ['@babel/syntax-dynamic-import'],
};
-
--package.json
--babel.config.js
---dir
----dir
-----build.js
not work.
Most helpful comment
@shkfnly I did just what was suggested above and changed my .babelrc file to a babel.config.js
.babelrc (removed):
babel.config.js (added):