英文:
React error in index.js, "Uncaught ReferenceError: dom is not defined"
问题
I'm building a React App,
I'm using Babel and Webpack as module bundler.
While writing the index.js the Application started sending me an error about the dom that is not defined,
but actually I've imported the "react-dom" library as the documentation has proposed to do.
Below I share the code, please help me.
package.json
"dependencies": {
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-router-dom": "^6.14.1"
},
"devDependencies": {
"@babel/cli": "^7.22.6",
"@babel/core": "^7.22.6",
"@babel/preset-env": "^7.22.6",
"@babel/preset-react": "^7.22.5",
"autoprefixer": "10.4.5",
"babel-loader": "^9.1.2",
"css-loader": "^6.8.1",
"html-webpack-plugin": "^5.5.3",
"style-loader": "^3.3.3",
"webpack-cli": "^5.1.4",
"webpack-dev-server": "^4.15.1"
}
index.js
import React from 'react';
import ReactDOM from 'react-dom/client';
const myFirstElement = <h1>Hello React!</h1>
const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(myFirstElement);
I've tried to install the library two times and also installed the "react-router-dom" library.
I made a simpler index.js that doesn't render the
I'm expecting to see the project running without problems.
英文:
I'm building a React App,
I'm using Babel and Webpack as module bundler.
While writing the index.js the Application started sending me an error about the dom that is not defined,
but actually I've imported the "react-dom" library as the documentation has proposed to do.
Below I share the code, please help me.
package.json
"dependencies": {
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-router-dom": "^6.14.1"
},
"devDependencies": {
"@babel/cli": "^7.22.6",
"@babel/core": "^7.22.6",
"@babel/preset-env": "^7.22.6",
"@babel/preset-react": "^7.22.5",
"autoprefixer": "10.4.5",
"babel-loader": "^9.1.2",
"css-loader": "^6.8.1",
"html-webpack-plugin": "^5.5.3",
"style-loader": "^3.3.3",
"webpack-cli": "^5.1.4",
"webpack-dev-server": "^4.15.1"
}
index.js
import React from 'react';
import ReactDOM from 'react-dom/client';
const myFirstElement = <h1>Hello React!</h1>
const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(myFirstElement);
I've tryed to install two times the library and installed the other one so called "react-router-dom".
I made a simpler index.js that doesn't render the <App/> from App.js, but It still does not work.
I'm expecting to see the projects running without problems.
答案1
得分: 0
你的ReactDom
导入语句似乎存在问题。请不要从"react-dom/client"
导入,而应该从"react-dom"
导入。如果你进行了更改,请告诉我更改是否有效。
英文:
Your ReactDom
import statement seems to be the issue. Instead of importing ReactDom from "react-dom/client";
import it from "react-dom";
. Please let me know if the change worked if/when you make the change.
答案2
得分: 0
为了解决这个问题,我在线寻求帮助,经过多个小时的研究,发现问题出在错误创建的bable文件中。
英文:
In order to solve this problem I've asked for help online, after many hours of researching the issue was found inside the bable file that was bad created.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论