Home > Net >  REACTDOM is not exported from react
REACTDOM is not exported from react

Time:08-17

I am trying to build my project of React, but the console throw this:

Failed to compile. Attempted import error: 'ReactDOM' is not exported from 'react' (imported as 'ReactDOM').

This is my package.json

package.json

this is my index.js

import React from "react";
import ReactDOM from "react-dom/client";

import "./index.css"; import App from "./App";
     
const root = ReactDOM.createRoot(document.getElementById("root"));

root.render(
  <React.StrictMode>
    <App />
  </React.StrictMode>
);

CodePudding user response:

Try this:

import React from "react"
import { StrictMode } from "react";
import { createRoot } from "react-dom/client";

import App from "./App";

const rootElement = document.getElementById("root");
const root = createRoot(rootElement);

root.render(
  <StrictMode>
    <App />
  </StrictMode>
);

CodePudding user response:

This error could suggest that you might not have react installed. I would suggest deleting your node_modules folder and package-lock.json file and running npm i in the terminal.

  • Related