-
-
Notifications
You must be signed in to change notification settings - Fork 6.3k
Description
Current Behavior
when i try to run the command npm start i get that error :
ERROR in ./main.js Module build failed (from ./node_modules/babel-loader/lib/index.js),
although i tried multiple solutions i found here but nothing seems to work with me yet !!
Expected Behavior
opens localhost with Hello world!!!
Input Code
App.js
import React, { Component } from 'react'; class App extends Component{ render(){ return( <div> <h1>Hello World</h1> </div> ); } } export default App;
Main.js
`import React from 'react';
import ReactDOM from 'react-dom';
import App from './App.js';
ReactDOM.render(, document.getElementById('app'));`
###index.html
`
<title>React App</title> <script src = 'index_bundle.js'></script> `Babel Configuration (.babelrc, package.json, cli command)
package.json
`{
"name": "example-2",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "webpack-dev-server --mode development --open --hot",
"build": "webpack --mode production"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"babel-core": "^6.26.3",
"babel-loader": "^8.1.0",
"babel-preset-env": "^1.7.0",
"react": "^16.13.1",
"react-dom": "^16.13.1",
"webpack": "^4.43.0",
"webpack-cli": "^3.3.11",
"webpack-dev-server": "^3.10.3"
},
"devDependencies": {
"@babel/preset-react": "^7.9.4",
"babel-preset-react": "^6.24.1",
"html-webpack-plugin": "^4.3.0"
}
}
`
webpack.config.js
`const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
module.exports = {
entry: './main.js',
output: {
path: path.join(__dirname, '/bundle'),
filename: 'index_bundle.js'
},
devServer: {
inline: true,
port: 8001
},
module: {
rules: [
{
test: /.jsx?$/,
exclude: /node_modules/,
loader: 'babel-loader',
query: {
presets: ['es2015', 'react']
}
}
]
},
plugins:[
new HtmlWebpackPlugin({
template: './index.html'
})
]
}`
.babelrc
{ "presets":["env", "react"] }
Environment:
node version--v12.16.3(x64)
npm version--6.14.4
OS: Windows 10
Additional context/Screenshots