我的React简单项目出现了编译错误。

huangapple go评论58阅读模式
英文:

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 &quot;react&quot;;
import ReactDOM from &quot;react-dom/client&quot;;
//..
const rootElement = ReactDOM.createRoot(document.getElementById(&quot;root&quot;));
rootElement.render(
 &lt;App /&gt;
)

or another way

import React from &quot;react&quot;;
import { createRoot } from &quot;react-dom/client&quot;;
//..
const rootElement = createRoot(document.getElementById(&quot;root&quot;));
rootElement.render(
 &lt;App /&gt;
)

huangapple
  • 本文由 发表于 2023年5月6日 15:54:02
  • 转载请务必保留本文链接:https://go.coder-hub.com/76187751.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定