Reputation: 2978
I have a project with React and Webpack as build system. My devDependencies
"webpack": "^4.5.0",
module: {
rules: [
{
test: /\.jsx?$/,
exclude: /node_modules/,
use: ['babel-loader'],
},
...
And I get this error:
ERROR in ./node_modules/project/components/InfiniteScroller.jsx Module parse failed: Unexpected token (9:8) You may need an appropriate loader to handle this file type.
What I am doing wrong?
Upvotes: 1
Views: 325
Reputation: 66355
It looks like you're including uncompiled code from node_modules, your loader specifically excludes compiling node_modules code (exclude: /node_modules/
) for efficiency reasons. Usually modules expose a compiled version of the library (usually in /dist, usually pointed to by "main" property in the package.json of the module).
If you want to parse code in node_modules, I recommend you just do it for node_modules/project
, rather than all modules for efficiency. Modify your exclude statement accordingly, something like: exclude: /node_modules(?!\/project)/
You'll also need to make sure you use the necessary presets to handle the files (e.g. babel-preset-env
, babel-preset-react
) and any plugins the file might need (e.g. transform-object-rest-spread
etc).
Upvotes: 2
Reputation: 1438
Since I don't have enough points to comment, I'll post as an answer -
I see you're importing a .jsx module - You should try adding
query: {
presets: ['es2015','react']
}
to your rule after use
Upvotes: 0