import React from "react" is required to work
Closed this issue · 7 comments
Hello. I'm using the project with the Anchor counter implementation. While it's working for me, I'm curious why I have to add import React from "react"; at the top of my files when I add a new page with a new component, even when using a structure exactly like one of the example components. "I tried to follow the steps described in this video from December 2023 (minute 37), and in the video, it's not required, but in my case, it is.
I also notice that I have to do imports like: import DemoFeature from "../../components/demo/demo-feature" instead of @/components/demo/demo-feature like the example files.
Although my code works, I'm just curious why this might be happening.
Hi there @0xNicko - could you share a reproduction of the issue you are facing? You should not have to add the global React import.
Hi, I'm not sure if this is the best way to reproduce the error. But there you can see that I added a new component. The component has the same code as the 'dashboard-feature.tsx' that comes by default. And if I don't import React, it gives me that error.
Please share a repository with your project that I can download and run locally. This way we can find out if there's something wrong in the app or there's an issue local to your system
Understood. I have cloned my project to this repository. Please let me know if it's okay. The new component I have generated is called "lab."
Thanks! Just pulled in the repo and ran it locally but it works fine here without the explicit imports. No errors in the editor or in the terminal where the dev server runs.
These are the versions of node and npm I'm using.
❯ node --version
v20.9.0
❯ npm --version
10.1.0
Are you seeing any errors when running npm run dev
or is it only in your editor?
Hi. I updated Node and NPM to the latest versions, redownloaded the project from my own repository, and it worked. Honestly, I can't figure out what the problem was, but making those adjustments worked. Sorry for creating the issue. Thank you!.
Hi. I updated Node and NPM to the latest versions, redownloaded the project from my own repository, and it worked. Honestly, I can't figure out what the problem was, but making those adjustments worked. Sorry for creating the issue. Thank you!.
Glad to hear that fixed it! Good luck with your new app! 🥳