英文:
my react simple project has a compiled error
问题
Module not found: Error: Package path ./client is not exported from package E:\React\react redux project\myapp\node_modules\react (see exports field in E:\React\react redux project\myapp\node_modules\react\package.json)
a simple react project for begin :
import React from "react";
import ReactDOM from "react-dom";
const root = ReactDOM.render(
Hello World!
,document.getElementById("root"));
英文:
Module not found: Error: Package path ./client is not exported from package E:\React\react redux project\myapp\node_modules\react (see exports field in E:\React\react redux project\myapp\node_modules\react\package.json)
a simple react project for begin :
import React from "react";
import ReactDOM from "react-dom";
const root = ReactDOM.render(<h1>Hello World!</h1>,document.getElementById("root"));
答案1
得分: 1
You should import react-dom/client
like this:
import React from "react";
import ReactDOM from "react-dom/client";
//..
const rootElement = ReactDOM.createRoot(document.getElementById("root"));
rootElement.render(
<App />
)
or another way:
import React from "react";
import { createRoot } from "react-dom/client";
//..
const rootElement = createRoot(document.getElementById("root"));
rootElement.render(
<App />
)
英文:
You should import react-dom/client
like this:
import React from "react";
import ReactDOM from "react-dom/client";
//..
const rootElement = ReactDOM.createRoot(document.getElementById("root"));
rootElement.render(
<App />
)
or another way
import React from "react";
import { createRoot } from "react-dom/client";
//..
const rootElement = createRoot(document.getElementById("root"));
rootElement.render(
<App />
)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论