При рендере данного кода JSX выдает ошибку в консоле
Как можно исправить? Читал, что нужно в HTML добавить тег скрипт с сорсом на js файл, не помогло
Uncaught Error: Target container is not a DOM element.
at Object.render (react-dom.development.js:26086)
at eval (index.jsx:9)
at Object../src/index.jsx (bundle.js:19)
at __webpack_require__ (bundle.js:133)
at bundle.js:156
at bundle.js:158
import React from 'react';
import ReactDOM from 'react-dom';
let block = document.querySelector('#app')
let content = <h2>Send</h2>
console.log('hi')
ReactDOM.render(content, block)
webpack.config.js:
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?jsx?$/,
exclude: /(node_modules|bower_components)/,
use: {
loader: 'babel-loader',
options: {
presets: ['@babel/preset-env', '@babel/preset-react']
}
}
}
]
},
plugins: [new HtmlWebpackPlugin()],
devServer: {
contentBase: path.join(__dirname, 'dist'),
compress: true,
port: 9000,
},
}
package.json:
{
"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/preset-react": "^7.13.13",
"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"
}
}