0

So I am trying run a react app locally that was originally developed on windows, on my system which is running Ubuntu 18.04. I use npm install --legacy-peer-deps as suggested by the original developer and the run npm start/npm run start. I encounter the following error from a whole bunch of files,

ERROR in ./src/components/ui/Task/Template/ReturnHomeTemplate.js 1:40-111 Module not found: Error: You attempted to import /home/praneet/SevenHub/node_modules/react-refresh/runtime.js which falls outside of the project src/ directory. Relative imports outside of src/ are not supported. You can either move it inside src/, or add a symlink to it from project's node_modules/.

In most of the files, the first line is

import React from "react";

and in some files it's not even that. Apparently the app does not use react-refresh explicitly anywhere.

There are warnings with npm install, but I was told that I can safely ignore them and don't have to audit fix them (I am new to react so I am not sure). I have tried reinstalling various node versions, removing node_modules and package-lock.json but am still unsuccessful in resolving the issue. Any pointers on this would be great, and happy to provide more information if necessary.

A few files where the error is thrown from for reference:

Index.js

import React from "react";
import ReactDOM from "react-dom";
import App from "./components/App";
import Header from "./components/ui/Header";
import { WorldProvider } from "./components/ui/ToolContext";
import { ROSProvider } from "./components/RosContext";
import { DndProvider } from "react-dnd";
import { HTML5Backend } from "react-dnd-html5-backend";

import UniversMap from "./components/ui/UniversMap/UniversMap";
import { Login } from "./components/ui/Login/Login";
import { FormantProvider } from "@formant/ui-sdk";

ReactDOM.render(
  <WorldProvider>
    <DndProvider backend={HTML5Backend}>
      {/* <Login /> */}

      <FormantProvider>
        <App />
      </FormantProvider>
    </DndProvider>
  </WorldProvider>,

  document.getElementById("root")
);

Navigation.js

import React from "react";
import LiveTvSharpIcon from "@material-ui/icons/LiveTvSharp";
import EditSharpIcon from "@material-ui/icons/EditSharp";
import BorderHorizontalSharpIcon from "@material-ui/icons/BorderHorizontalSharp";
import StreetViewSharpIcon from "@material-ui/icons/StreetviewSharp";
import EqualizerSharpIcon from "@material-ui/icons/EqualizerSharp";
import ListAltSharpIcon from "@material-ui/icons/ListAltSharp";
import TodayOutlinedIcon from "@material-ui/icons/TodayOutlined";
import robotIcon from "../../assets/robotlogo.png";
import MapOutlinedIcon from "@material-ui/icons/MapOutlined";
import TaskItem from "./Taskitem";
import TaskTabs from "./../ui/TaskTabs";
import RobotList from "./Robots/RobotList";
import { userDemoData } from "./User/Users";
import Users from "./User/Users";

const routes = [
  "/dashboard",
  "/robots",
  "/maps",
  "/tasks",
  "/users",
  "/settings",
  "/newmap",
];

const taskTabs = [{ id: 1 }];

const dashboardMappings = {
  Live: <LiveTvSharpIcon />,
  Layout: <EditSharpIcon />,
  test: <EditSharpIcon />,
  Zones: <BorderHorizontalSharpIcon />,
  Streams: <StreetViewSharpIcon />,
  Stats: <EqualizerSharpIcon />,
  Logs: <ListAltSharpIcon />,
};

const taskList = [
  { id: 1, task: "sort", user: "A" },
  { id: 2, task: "Collaboration", user: "B" },
  { id: 3, task: "queue", user: "C" },
];
const robotList = [
  { id: 1, name: "Robot1" },
  { id: 2, name: "Robot2" },
];

const drawerMappings = {
  dashboard: dashboardMappings,

  robots: {
    list: [<RobotList />],
    icon: <img src={robotIcon} style={{ maxWidth: "24px" }} />,
    active: [],
  },
  maps: {
    list: ["Map1", "Map2", "Map3", "Map4"],
    icon: <MapOutlinedIcon />,
    active: [],
  },

  tasks: {
    list: [<TaskTabs />], //taskTabs.map((item) => <TaskTabs />),

    active: [],
  },

  // tasks: {
  //   list: taskList.map((item) => (
  //     <TaskItem task={item.task} id={item.id} user={item.user} />
  //   )),
  //   icon: <TodayOutlinedIcon />,
  //   disabled: true,
  //   active: [],
  // },
  users: {
    list: [<Users />],
    icon: <MapOutlinedIcon />,
    active: [],
  },
};

export { routes, dashboardMappings, drawerMappings, robotList };

enter image description here

Pran-7
  • 23
  • 5
  • Please, provide the contents of the files where the errors appear (UniversMap.tsx, UserDetails.js, etc). – dragomirik Dec 22 '22 at 19:13
  • there is a possibility you have installed the module globally and using it and now its not working try installing it locally once and check if the issue resolves – innocent Dec 22 '22 at 19:30
  • @innocent is there a particular flag that I have to enable to install it locally? When I installed react-refresh, I did `npm install react-refresh --legacy-peer-deps`, from the project folder – Pran-7 Dec 22 '22 at 20:11
  • @dragomirik I have added the examples, hope that helps – Pran-7 Dec 22 '22 at 20:17
  • Please delete the npm lock file and then install node modules again. This has worked for me many times – Rahul Purohit Dec 22 '22 at 23:40
  • Please also share your npm version – Rahul Purohit Dec 22 '22 at 23:43
  • If you are talking about package-lock.json, I have deleted and reinstalled again. I am not sure if npm lock id different, if so, please let me know how to delete that. npm version - 6.14.17 – Pran-7 Dec 23 '22 at 13:06
  • Not sure if this works for a deployment model, but since I mostly make changes and test it locally, the issue was overcome by launching with `FAST_REFRESH=false npm start` which I found on another question a few days back (hence the lack of a link). – Pran-7 Feb 04 '23 at 11:06

2 Answers2

1

If @dragomirik answer not fixing this issue, try this as well.

This issue is mostly happening due to version mismatch issue of react-refresh

Try to run npm ls react-refresh. You'll get a deps-tree like below, and check which has different version of react-refresh

for example in my terminal,

├─┬ @storybook/preset-create-react-app@4.1.2
│ └─┬ @pmmmwh/react-refresh-webpack-plugin@0.5.10
│   └── react-refresh@0.14.0
├─┬ @storybook/react@6.4.19
│ ├── @pmmmwh/react-refresh-webpack-plugin@0.5.10 deduped
│ └── react-refresh@0.11.0
└─┬ react-scripts@5.0.0
  ├── @pmmmwh/react-refresh-webpack-plugin@0.5.10 deduped
  └── react-refresh@0.11.0

You might can temporary fix this issue by installing react-refresh as dev dependency by npm install -D react-refresh@0.11.0. or running npm dedupe

[EDIT]: you can use overrides in package.json as well

{

  "dependencies": {
    ...
  },
  "devDependencies": {
    ....
  },
  "overrides": {  
    "react-refresh": "version"
  }
}

I was also struggled with this issue and spent hours to fix this, also check this related issue for more insights. Good luck !

Nithin CV
  • 1,046
  • 9
  • 23
0

It's hard to provide you with a proper solution, but we can investigate. Try these 3 things:

I) Reinstall node.

  1. Remove node_modules, package-lock.json, yarn.lock (if you have it) from your project. Clear cache (npm cache clean --force).
  2. Completely remove node from your computer (How to completely remove node.js from Windows).
  3. Install node. Try the one that you have now (I may assume that the problem is not related to the node version).
  4. Install packages in your project.

II) Issue with the path Remove the line import robotIcon from "../../assets/robotlogo.png";. The error is related to importing the data outside of ./src directory, maybe the issue is here. If the number of errors will decrease, please, let me know.


III) Replace:

ReactDOM.render(
  <WorldProvider>
    <DndProvider backend={HTML5Backend}>
      {/* <Login /> */}

      <FormantProvider>
        <App />
      </FormantProvider>
    </DndProvider>
  </WorldProvider>,

  document.getElementById("root")
);

with

ReactDOM.render(
  <div>text</div>,
  document.getElementById("root")
);

If the errors are left, provide the list. If the errors disappeared, try:

ReactDOM.render(
  <WorldProvider>
    <DndProvider backend={HTML5Backend}>
      <FormantProvider>
        <div>text</div>
      </FormantProvider>
    </DndProvider>
  </WorldProvider>,

  document.getElementById("root")
);

Removing the parts of the code, you will localize the error(s).


Also:

  1. Provide the contents of the files where the errors appear (UniversMap.tsx, UserDetails.js, etc). So far, just index.js and Navigation.js are provided, they don't have the errors following your screenshot and they are less useful rather than files with the errors.
  2. Text of all errors including the details provided with the number of the errors (not on a screenshot, but in a text format).
dragomirik
  • 612
  • 2
  • 6
  • 13
  • Hello @dragmirik, thanks a lot for taking the time out to provide such a detailed response. I) Remove Node 1. Removed the files and tried again, but the issue persists. 2. I am running it on Linux, the application was originally built on Windows. I did a purge, checked and deleted nvm,npm and node folders with `whereis` and reinstalled one version after the other and the issue still persists II) Will try this and update III) Will try this as well and update 1. The same error occurs in index and navigation as well, probably should have mentioned that when adding the files. – Pran-7 Dec 23 '22 at 12:59
  • The error log is as follows: https://pastebin.com/VQtQZxYG – Pran-7 Dec 23 '22 at 13:04
  • I have tried both II and III, unfortunately the same errors were produced and there was no decrease in the number of errors – Pran-7 Dec 23 '22 at 13:28
  • @Pran-7 1) Have you cleared the cache after deleting the node? 2) Do you use the storybook? Multiple issues on the Internet are related to the version of the storybook (one of them: https://github.com/storybookjs/storybook/issues/17049). 3) Pls, provide the contents of package.json. 4) I am not sure that it will help, but sometimes weird things make it work: install yarn, remove node_modules, install dependencies using yarn (`yarn install` in the dir with package.json, yarn is the same package manager as npm). – dragomirik Dec 24 '22 at 00:19
  • I believe that this issue is not related to the OS. However, it may be related to the version of node. – dragomirik Dec 24 '22 at 00:21
  • 1
    Not sure if this works for a deployment model, but since I mostly make changes and test it locally, the issue was overcome by launching with `FAST_REFRESH=false npm start` which I found on another question a few days back (hence the lack of a link). – Pran-7 Feb 04 '23 at 11:06