question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

JSX is not transform by babel loader from node_modules/my_module

See original GitHub issue

I’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:closed
  • Created 7 years ago
  • Reactions:9
  • Comments:10 (2 by maintainers)

github_iconTop GitHub Comments

4reactions
renatonmendescommented, Mar 16, 2018

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?

3reactions
ciclooncommented, Feb 17, 2017

Solved the issue by replacing

path.resolve(__dirname, './node_modules/shared-components/src') with fs.realpathSync(path.resolve(npmBase, './shared-components/src'))

Read more comments on GitHub >

github_iconTop Results From Across the Web

Babel not running on imports from `node_modules` via ...
Either webpack or babel is deciding to not apply babel transforms to files in node_modules , and it's not clear how to workaround...
Read more >
Using with webpack · Jest
Non -Babel JavaScript transformations can be handled with Jest's transform config option. Handling Static Assets #. Next, let's configure Jest to gracefully ...
Read more >
babel/preset-react
Though the JSX spec allows this, it is disabled by default since React's JSX does not currently have support for it. pure. boolean...
Read more >
babel-loader - npm
babel module loader for webpack. ... be transforming the node_modules folder or other unwanted source. ... ProvidePlugin will not work:.
Read more >
Using Webpack with React, Pt. 1 - Toptal
[contenthash:8].js", publicPath: "/" + }, + module: { + rules: [ + { + test: /\.jsx?$/, + exclude: /node_modules/, + use: { +...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found