Answer the question
In order to leave comments, you need to log in
Babel-loader not working?
Installed webpack, installed babel, run webpack-dev-server and writes an error in the terminal:
ERROR in ./src/index.jsx 6:13
Module parse failed: Unexpected token (6:13)
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
| let block = document.querySelector('#app')
|
> let button = <button>Send</button>
webpack 5.37.1 compiled with 1 error in 191 ms
ℹ 「wdm」: Failed to compile.
const path = require('path')
const HtmlWebpackPlugin = require('html-webpack-plugin');
module.exports = {
entry: './src/index.jsx',
output: {
filename: 'bundle.js',
path: path.resolve(__dirname, 'dist')
},
module: {
rules: [
{
test: /\.m?js$/,
exclude: /(node_modules|bower_components)/,
use: {
loader: 'babel-loader',
options: {
presets: ['@babel/preset-env']
}
}
}
]
},
plugins: [new HtmlWebpackPlugin()],
devServer: {
contentBase: path.join(__dirname, 'dist'),
compress: true,
port: 9000,
},
}
{
"name": "first-react",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"dev": "webpack serve --mode development",
"build": "webpack --mode development"
},
"browserslist": "> 0.25%, not dead",
"repository": {
"type": "git",
"url": "git+https://github.com/Marat20/First-React.git"
},
"keywords": [],
"author": "",
"license": "ISC",
"bugs": {
"url": "https://github.com/Marat20/First-React/issues"
},
"homepage": "https://github.com/Marat20/First-React#readme",
"devDependencies": {
"@babel/core": "^7.14.3",
"@babel/preset-env": "^7.14.2",
"babel-loader": "^8.2.2",
"html-webpack-plugin": "^5.3.1",
"webpack": "^5.37.1",
"webpack-cli": "^4.7.0",
"webpack-dev-server": "^3.11.2"
},
"dependencies": {
"react": "^17.0.2",
"react-dom": "^17.0.2"
}
}
Answer the question
In order to leave comments, you need to log in
module: {
rules: [
{
test: /\.m?js$/,
exclude: /(node_modules|bower_components)/,
use: {
loader: 'babel-loader',
options: {
presets: [
'@babel/preset-env',
'@babel/preset-react' // установить этот пакет в dev-dependencies
]
}
}
}
]
},
{
"presets": [
[
"@babel/preset-env",
{
"corejs": 3,
"modules": false,
"useBuiltIns": "usage"
}
],
"@babel/preset-react"
],
"plugins": [
"@babel/plugin-syntax-dynamic-import",
"@babel/plugin-proposal-optional-chaining"
]
}
module: {
rules: [
{
test: /\.(js|jsx)$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader'
}
},
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question