I have a project with React and Material Kit React framework and I need NavPills from Material Kit React. However, when I try to run the npm server, I get this error:
ERROR in ./node_modules/material-kit-react/src/components/NavPills/NavPills.js 36:4
Module parse failed: Unexpected token (36:4)
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
| });
| const tabButtons = (
> <Tabs
| classes={{
| root: classes.root,
@ ./src/components/Store.js 13:16-78
@ ./src/app.js
Which is weird because I think that Tabs
doesn't need a loader. Or am I missing something?
Here is my package.json
:
{
"name": "Front_KRIG",
"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.26.0",
"babel-core": "^6.26.3",
"babel-loader": "^7.1.5",
"babel-plugin-transform-class-properties": "^6.24.1",
"babel-preset-env": "^1.7.0",
"babel-preset-react": "^6.24.1",
"braces": "^3.0.2",
"css-loader": "^3.6.0",
"kind-of": "^6.0.3",
"live-server": "^1.2.1",
"material-kit-react": "^1.9.0",
"normalize.css": "^8.0.1",
"path": "^0.12.7",
"react": "^16.13.1",
"react-dom": "^16.13.1",
"react-modal": "^3.11.2",
"react-router-dom": "^5.2.0",
"sass-loader": "^8.0.2",
"style-loader": "^1.2.1",
"webpack": "^4.44.1",
"webpack-dev-server": "^3.11.0"
},
"devDependencies": {
"node-sass": "^4.14.1",
"webpack-cli": "^3.3.12"
}
}
webpack.config.js
:
const path = require("path");
module.exports = {
entry: "./src/app.js",
output: {
path: path.join(__dirname, "public"),
filename: "bundle.js"
},
mode: "development",
module: {
rules: [
{ loader: "babel-loader", test: /\.js$/, exclude: /node_modules/ },
{
test: /\.s?css$/,
use: ["style-loader", "css-loader", "sass-loader"]
},
]
},
devtool: "eval-cheap-module-source-map",
devServer: {
contentBase: path.join(__dirname, "public"),
historyApiFallback: true
}
};
Should I add to webpack.config.js
in module.rules
something like this?:
{
test: /\.jsx?$/,
use: ["babel-loader"]
}
Or do I need another loader?
Your NavPills.js
file uses JSX, and it's the JSX that the error is pointing to. The parser needs to know it's processing a JSX file, not just a normal JavaScript file. Typically you do that by using the extension .jsx
instead of .js
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.