'Error when running npx create-react-app myapp on fresh install of node.js
I followed the reactjs.org website for create-react-app to a T
I haven't been able to find this specific error anywhere, and most posts are years old; irrelevant to the specific error in the post anyways.
Has anyone had this happen and what did you do to fix it?
Latest version of Win10 if that helps. The LTS version v16.14.0 of Node.js
My Node.js installation is just a clean express installation on the OS drive. Any ideas?
The error message is below as-is after runnning npx create-react-app my-app
:
C:\Users\Keith & Vanny>npx create-react-app myapp
'Vanny\AppData\Local\npm-cache\_npx\c67e74de0542c87c\node_modules\.bin\' is not recognized as
an internal or external command,
operable program or batch file.
node:internal/modules/cjs/loader:936
throw err;
^
Error: Cannot find module 'C:\Users\create-react-app\index.js'
at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
at Function.Module._load (node:internal/modules/cjs/loader:778:27)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:77:12)
at node:internal/main/run_main_module:17:47 {
code: 'MODULE_NOT_FOUND',
requireStack: []
}
Update: I installed it locally through npm i create-react-app
and tried to create with npm init react-app my-app
.
They both yield the same error above. I think it has something to do with that unrecognized command part of the error where a batch script was ran and it failed to parse and do the job, and then the package didn't get installed. So the javascript jargon is telling me I'm missing required packages; my path
s for Node are perfect. Clean install and clean of any packages. This's got me stumped. Looks like I'm going to the devs if we can't figure this out.
Solution 1:[1]
Creating a local admin account that's just a single string with no symbols or spaces, logging into that account, and then running the npx command worked perfectly.
Installing ReactJs on a Windows machine with a users/ path that contains symbols and spaces, particulary symbols, causes a bug to happen in which npx/npm or even create-react-app can't properly parse the path to the module, therefore throwing a can't find module error.
Lesson learned: never put symbols in your windows username. Pretty bummed I have to develop on the local account for sure though.
Update: Because I refuse to use a dummy admin account to develop on I found the perfect solution working on Win 10 Home in 2022 perfectly fine. Just create a system restore point before you do it. Here's the link! StackExchange solution for properly renaming a faulty conflicting system username. Use the second solution, not the accepted answer.
Just be prepared to spend some hours editing your registry.
Solution 2:[2]
this worked for me: npx create-react-app@latest myapp
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | |
Solution 2 |