Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file."

Tags:

css

reactjs

I'm setting up webpack to my react project using yarn and this error appears:

ERROR in ./src/app.js 67:6 Module parse failed: Unexpected token (67:6) You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders ℹ 「wdm」: Failed to compile.

webpack.config.js

const path = require("path");  module.exports = {     entry: "./src/app.js",     output: {         path: path.join(__dirname, 'public'),         filename: 'bundle.js'     },     module:{         rules:[{             loader: 'babel-loader',             test: '/\.(js|jsx)$/',             exclude: /node_modules/         }]     },     devtool: 'cheap-module-eval-source-map',     devServer: {         contentBase: path.join(__dirname, 'public')     } } 
.babelrc {     "presets": ["env", "react","@babel/preset-env"],     "plugins": [         "transform-class-properties"     ] } 

package.json

{   "name": "react",   "version": "1.0.0",   "main": "index.js",   "license": "MIT",   "scripts": {     "serve": "live-server public/",     "build": "webpack",     "dev-server": "webpack-dev-server"   },   "dependencies": {     "babel-cli": "6.24.1",     "babel-core": "6.25.0",     "babel-plugin-transform-class-properties": "6.24.1",     "babel-preset-env": "1.5.2",     "babel-preset-react": "6.24.1",     "live-server": "^1.2.1",     "react": "^16.9.0",     "react-dom": "^16.9.0",     "webpack": "^4.39.3",     "webpack-dev-server": "^3.8.0"   },   "devDependencies": {     "@babel/core": "^7.6.0",     "babel-loader": "^8.0.6",     "webpack-cli": "^3.3.8"   } } 
like image 386
Abdalrahman Avatar asked Sep 13 '19 13:09

Abdalrahman


2 Answers

You are using unnecessary escape character: which is not required.

Replace test: '/\.(js|jsx)$/', with test: /\.js$|jsx/, it should work fine.

I replicated your issue in my machine and found the same which is resolved by the above fix.

hope this helps, happy coding!!!

like image 129
Darpan Rangari Avatar answered Sep 16 '22 15:09

Darpan Rangari


The selected answer missing some details:

It should be test: /\.js|\.jsx$/

\: is an escape character in this case for .

|: is an Alternation / OR operand

$: is end of line

Hopefully this is useful for you.

Source: https://www.rexegg.com/regex-quickstart.html

like image 42
fadly kayo Avatar answered Sep 16 '22 15:09

fadly kayo