Invalid Options Argument when creating react app

I am currently going through the react course freecodecamp have for beginners in the channel and have hit an issue and hope you will be able to help with it.

I am currently just trying to create a react app. I have been trying to use the command npx create-react-app {project name} but it keeps saying that it has an Invalid options argument. I have tried npm -g uninstall create-react-app and clearing the cache and reinstalling the package but it has the same error.

I’m wondering what is wrong with my command. Please help!

So I had asked people in StackExchange and someone had asked me to try updating my npm with ‘npm install -g npm@latest’ and for whatever reason, I got the same error message again! (Hoping that this might give a better picture of my error.) Thanks for the thought tho.

Also, my node js version is v16.13.0 and npm is 8.1.0

Instead of:

npm -g uninstall create-react-app

its usually:

npm uninstall -g create-react-app

I’m not sure which cache, or how it was done so I’m not sure if this is important.

npx will automatically install the package (create-react-app) and run it by default, so you shouldn’t need to install anything. It will intelligently load locally installed packages, or globally installed ones if available.

However, this might not be the behavior you want, as if your locally installed, or globally installed version is old, you’d be running an older version. Where-as if nothing was installed locally or globally, npx will get the latest and run it. This is usually the preferred behavior when running scripts such as create-react-app, which are executed to create a new project from scratch, where you’d like to have the latest versions before getting started.

I’d suggest uninstalling the global version, and possibly local versions, along with posting what’s in the debug log mentioned in the error to help debug it.

I agree, make sure you have uninstalled the global. It might be worth uninstalling and reinstalling Node/npm as well.

Does it happen with npm init as well?

npm init react-app my-app

Maybe also try Yarn just to test.

yarn create react-app my-app

Another option is to use Vite.

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

I haven’t used Vite that much (it’s really fast though) and for your learning-type projects, it should work just fine.

I actually tried uninstalling and reinstalling nodejs when this happened and tried everything again and it did not work. This is a picture for the error log, hope it can give a better clarification? Thanks a lot for helping by the way.

Thanks for helping but just in relation to reinstalling I have actually reinstall nodejs and npm to no avail. I have uploaded a snap of the error log if it gives more clarification. Again thanks for helping

Are you using nvm? Because some of the paths seem to suggest so. I haven’t really used nvm but the version number in the path might suggest you are running node v11 (I might be wrong).

Also, the command seems to suggest that you are still trying to install it globally?

1 Like

So this is what happens when i tried to type in npm install/uninstall. I do not think I am using nvm.

this is the error log that I am getting. I seriously do not know what is going on :disappointed_relieved:

Delete the lockfile + node modules in your project. You seem to have had a much older version of Node somehow installed

Edit: you don’t need to install npm either, it comes with Node, has done for a very long time now

Hi, sorry I don’t know what is lockfile and node modules in my project since it is currently empty.

I have actually solved the problem, for some reason, there are two versions in my nvm file, an older version 11 and a newer version 14. For some reason the nvm was using the older version 11 so I had to use the ‘nvm use 14’ to change to the latest version and that worked.

Anyways, thank you all for helping. Hope y’all have a great day.

Edit: OK so you are running nvm, never mind.

This part of your path is what I’m referring to.


What happens if you run nvm use newest from the command line?

Edit2: Just as an aside, unless you need it I wouldn’t suggest using nvm. Especially not if you are going to forget about it and end up using older versions of Node/npm.

If you stick with nvm (and there’s no issue with that you just need to be aware that theres a program managing Node that lets you switch versions. Y probably don’t need it though as @lasjorg says), then make sure to set the one you want as default as the default, ie nvm alias default 14 or whatever you want the default to be out of the installed versions you have.

Also re lockfiles, a lockfile is generated in every npm project when you run npm install, it’s called package.lock, and it is a file that specifies exactly what is installed.

The error you were getting that mentioned it was because you had something installed using a much earlier version of Node, then were trying to run npm using a newer version of Node. The way the package.lock file is structured changed between the versions, so yours was wrong for Node 14. You can just delete it, a new one will be generated every time npm install runs

I see, welp I’m glad that it is solved now thanks for the info 2. By the way, when I delete nvm folder directly, I can’t use any of the npm commands, is there a way to delete nvm without affecting that?

I know it’s too late now but you shouldn’t just delete the folder. The windows version of nvm comes with an installer/uninstaller. Uninstall it correctly then reinstall Node just to be on the safe side.

Ahh I see, well I did restore it and it worked out fine. I am going to finish up my course then uninstall nvm that way. Thank you so much for helping.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.