JSX is not transform by babel loader from node_modules/my_module
See original GitHub issueI’m submitting a feature request
Webpack Version: 2.2.1
Babel Core Version: 6.22.1
Babel Loader Version: 6.2.10
Please tell us about your environment: OSX 10.12.3
Current behavior:
I’m using a separate github repo to store all react components that get used in multiple apps we create. When I try to import a JSX file with Webpack, I get the following You may need an appropriate loader to handle this file type.
whenever the file contains JSX. Other es6 content seems to compile correctly. And JSX content in my normal app/src folder compile correctly
Expected/desired behavior: Compile are JSX content from all “include” folders
- If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem along with a gist/jsbin of your webpack configuration.
Project Directory
|
|--node_modules
| |--shared-components
| | |--src
| | | |--test.jsx
|--src
| |--app.jsx
.babelrc
.webpack.config.js
package.json
webpack.config.js
module: {
rules: [
{
include: [
path.resolve(__dirname, './src'),
path.resolve(__dirname, './node_modules/shared-components/src'),
],
test: /\.(js|jsx)$/,
use: [
{
loader: 'babel-loader',
options: {
cacheDirectory: true,
},
},
],
},
.babelrc
{
"plugins": ["dynamic-import-webpack"],
"presets": [
"latest",
"react",
"stage-3"
],
"env": {
"test": {
"plugins": ["istanbul"]
}
}
}
src/app.jsx
compiles correctly. However when src/app.jsx
imports node_modules/shared-components/src/test.jsx
, webpack throws
Module parse failed: /.../shared-components/src/test.jsx Unexpected token (5:4)
You may need an appropriate loader to handle this file type.```
Issue Analytics
- State:
- Created 7 years ago
- Reactions:9
- Comments:10 (2 by maintainers)
I’m having the same problem, except that the symlink was created with the command:
$ npm install --save ../my_shared_code
Any plans to solve that in the near future?
Solved the issue by replacing
path.resolve(__dirname, './node_modules/shared-components/src')
withfs.realpathSync(path.resolve(npmBase, './shared-components/src'))