React installation issues

Hello there. So I’m starting to learn React (which I love) and am having some confusion installing the module. Here is the error I get

'React' is declared but never read

And I’m not great w/ the CMD and tried installing Expo as well. Can someone please help?


Some more like a warning. Like if you import something but do not use it.

The requirement for importing React was removed in React 17 (docs) before that you had to import it into every component.

How are you installing React? I would suggest using Vite

Expo is for native apps and you would likely be using React Native and not just React. If you are just starting out learning React I would suggest you start with plain React and get that down a bit first before moving to React Native.

1 Like

I agree w/ that and am biting off more than I can currently lol. Good looking out. And it was native yes.

Update: I don’t know what I’m reading lol. I know how to use a little of the CMD in Windows but I don’t know what Scaffolding is either. So I’m not sure where to start w/ these docs.

Also, I have node and powershell installed.

For command line/console/terminal stuff, I generally recommend using a bash based terminal. If you have Git installed locally you can use the Git Bash terminal.

There’s nothing wrong with CMD or Powershell, but when you’re troubleshooting a problem the advice you find will almost always be in syntax for bash.

1 Like is what I used, before I moved to WSL.

Yeah I’m still having issues lol. When I copy the GIT (npm) code into my installed Windows GIT, it gives me an issue.

Update: Also, I’m not being lazy, clearly, but this is all a little overwhelming and I honestly know more React than the installation lol. I don’t like this part.

User@User-PC MINGW64 ~ $

That’s what I get when I open GIT fresh.

Shouldn’t really matter which terminal you use. Just as long as you have node/npm installed.

  • Create/open the folder where you want the project folder to be.

  • Right-click an empty space inside the folder and select “Git Bash Here”

  • Run the command

npm create vite@latest

Follow the prompts to create a React app.

So I downloaded and installed Gitbash and Node which I was told I needed. But that’s where things got confusing.

What is confusing?

Open any terminal in the location you want the project and run the command I showed.

I don’t know how to make a folder in a terminal or what that means lol. Guess I have to unfortunately learn that to code in React then?

No, it doesn’t have to be from the command line, but it’s mkdir someFolderName in bash if you need it.

  • Just create a folder somewhere for all your web projects to live in. I’m sure you know how to make a folder normally.

  • Go inside that folder and right-click in an empty space.

  • From the context menu select “Git Bash Here” or “Open in terminal” (if you do not see any such menu use “Shift + Right-click” you should see some option for a terminal.

  • From the terminal run the npm command already posted and follow the prompts.

Or just run

npm create vite@latest my-react-app -- --template react

Now cd into the new folder cd my-react-app and run npm i then after it is done run npm dev

Or open the folder in VS Code and from the menu item “Terminal” select “New Terminal”. Then run the npm i and npm dev from inside VS Code.

Or use an online editor to learn in.

I’m sorry if I added to the confusion. I wasn’t trying to imply that you need a bash shell in order to build a React project. I just saw that you were asking for help and that you mentioned which terminal software you used, so I was suggesting that terminal commands that you see in instructions are probably a different syntax.

We can’t really do more than guess when it comes to problems with your local development environment.

React is a library. You can add it to your package via a package manager like npm or yarn. Then you can start writing React components. If you added the package but haven’t used React methods yet, that would explain the warning you mentioned in your first post.

If you’re building a new React project and you want to quickstart it, you can use create react app.

Well I appreciate the help and the clearing up on the confusion. I just need to create a folder from/in my Git bash and then (apparently? lol) I should be able to start importing and working on project tutorials.

Update: Here is what I get when I copy over the code from the link into my Git.

Screenshot 2022-11-11 14.14.06

Also, how is this THAT hard? lmao.

It looks like you probably didn’t add the node directory to your system PATH variable. In order to use a command, the computer has to know the location of the files that contain that command.

Fair enough. So I …

  1. Need to make a directory (main) folder to hold my project? O my project AND my other folders?
  2. Import react from react?

And that’s all?

Did you get Node working or what?

The PATH is set up when you install Node.js unless you intentionally uncheck the option. Maybe just uninstall and reinstall Node.js and make sure not to change the install settings.

You can also use nvm-windows which can be nice (let you switch node versions on the fly)

I would really not suggest using create-react-app, it is slow as molasses compared to Vite.

Here is a terminal-only install.

This will install it to a folder on your desktop for convenience (the code . command assumes you have VS Code installed).

Start menu > type “git bash” and hit Enter.

Run each command, one at a time.

cd desktop
mkdir websites
cd websites
npm create vite@latest my-react-app -- --template react
cd my-react-app
npm i
code .
npm run dev

Here is what happened when I ran your code line by line.
Screenshot 2022-11-12 10.25.49

Did you reinstall Node.js?

What you you get back from node -v and npm -v

What happens if you run the npm install command from PowerShell instead?

Not sure about the Powershell. I’ll try and let you know.

If your Node.js install is broken it won’t help.

You didn’t answer the question. Did you reinstall Node?