Reputation: 21
I'm having an error running the webpack dev script, this is the error.
This are the codes:
App.js
import React from "react";
import ReactDOM from "react-dom";
import DataProvider from "./DataProvider";
import Table from "./Table";
import Form from "./Form";
const App = () => (
<React.Fragment>
<DataProvider endpoint="api/lead/"
render={data => <Table data={data} />} />
<Form endpoint="api/lead/" />
</React.Fragment>
);
const wrapper = document.getElementById("app");
wrapper ? ReactDOM.render(<App />, wrapper) : null;
package.json
{
"name": "amazona_project",
"version": "1.0.0",
"main": "index.js",
"scripts": {
"dev": "webpack --mode development ./amazona/frontend/src/index.js --output ./amazona/frontend/static/frontend/main.js",
"build": "webpack --mode production ./amazona/frontend/src/index.js --output ./amazona/frontend/static/frontend/main.js"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"@babel/core": "^7.1.6",
"@babel/preset-env": "^7.1.6",
"@babel/preset-react": "^7.0.0",
"babel-loader": "^8.0.4",
"babel-plugin-transform-class-properties": "^6.24.1",
"prop-types": "^15.6.2",
"react": "^16.6.3",
"react-dom": "^16.6.3",
"webpack": "^4.25.1",
"webpack-cli": "^3.1.2"
},
"dependencies": {},
"description": ""
}
webpack.config.js
module.exports = {
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: "babel-loader"
}
}
]
}
};
.babelrc
{
"presets": [
"@babel/preset-env", "@babel/preset-react"
],
"plugins": [
"transform-class-properties"
]
}
I'm sure the problem has something to do with the syntax, but I dont understand which part is wrong in my code. I would really appreaciate the help, thanks in advance.
Upvotes: 2
Views: 300
Reputation: 96
You will need to setup a .babelrc file and webpack.config.js
The .babelrc file should contain
{
"presets": ["@babel/preset-env", "@babel/preset-react"]
}
The webpack.config.js should contain
module.exports = {
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: "babel-loader"
}
}
]
}
};
You can use this link as reference in setting up your project
Upvotes: 1