facebook / create-react-app

Set up a modern web app by running one command.
https://create-react-app.dev
MIT License
102.69k stars 26.84k forks source link

create-react-app fails due to node_modules being created in a wrong directory on Windows #3326

Closed LeonelAV closed 6 years ago

LeonelAV commented 6 years ago

Is this a bug report?

yes

Can you also reproduce the problem with npm 4.x?

(Write your answer here.)

Which terms did you search for in User Guide?

(Write your answer here if relevant.)

Environment

  1. node -v: 6.10.2
  2. npm -v:4.6.1
  3. yarn --version (if you use Yarn):
  4. npm ls react-scripts (if you haven’t ejected):

Then, specify:

  1. Operating system: windows 10
  2. Browser and version (if relevant):

Steps to Reproduce

(Write your steps here:)

  1. npm install -g create-react-app
  2. create react app name-of-my-project
  3. starts to install react, react-dom and react-scripts and before finish i get an error: Aborting Instalation

Aborting installation.
Unexpected error. Please report it as a bug:
{ Error: Cannot find module 'C:\Users\leonel\Desktop\pseudogram\node_modules\react- scripts\package.json'
at Function.Module._resolveFilename (module.js:469:15)
at Function.Module._load (module.js:417:25)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
at checkNodeVersion (C:\Users\leonel\AppData\Roaming\npm\node_modules\create-re act-app\createReactApp.js:476:23)
at getPackageName.then.then.then.packageName (C:\Users\leonel\AppData\Roaming\n pm\node_modules\create-react-app\createReactApp.js:283:7)
at process._tickCallback (internal/process/next_tick.js:109:7) code: 'MODULE_NO T_FOUND' }

Deleting generated file... package.json
Deleting pseudogram / from C:\Users\leonel\Desktop
Done.

Expected Behavior

I expect it create the folder project

Actual Behavior

Aborting installation.
Unexpected error. Please report it as a bug:
{ Error: Cannot find module 'C:\Users\leonel\Desktop\pseudogram\node_modules\react- scripts\package.json'
at Function.Module._resolveFilename (module.js:469:15)
at Function.Module._load (module.js:417:25)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
at checkNodeVersion (C:\Users\leonel\AppData\Roaming\npm\node_modules\create-re act-app\createReactApp.js:476:23)
at getPackageName.then.then.then.packageName (C:\Users\leonel\AppData\Roaming\n pm\node_modules\create-react-app\createReactApp.js:283:7)
at process._tickCallback (internal/process/next_tick.js:109:7) code: 'MODULE_NO T_FOUND' }

Deleting generated file... package.json
Deleting pseudogram / from C:\Users\leonel\Desktop
Done.

Timer commented 6 years ago

Try to clear your npm cache.

LeonelAV commented 6 years ago

I already did that and still does not work

gaearon commented 6 years ago

Can you try with some other npm version? e.g. maybe npm 5

LeonelAV commented 6 years ago

@gaearon i tried with other versions of npm(included npm 5) and node and still got the same problem.

LeonelAV commented 6 years ago

i tried again with new versions of npm and nothing. Still same problem

LeonelAV commented 6 years ago

I realize that the node_modules folder is created in another folder and not in the folder of the project, thats why it can´t found the module i guess... how can i solve this? @Timer @gaearon

davidr9 commented 6 years ago

I am experiencing the exact same issue. I also noticed the node_modules folder is created outside the project in question, directly in my C drive.

npm version: 3.10.10 node version: 6.9.5

OS: Windows 7

My friend attempted to replicate the issue using the exact same steps on a Mac, but the app was created as expected for him.

Timer commented 6 years ago

Unfortunately, we're ill-equipped to provide support for bugs like these.

Make sure you actually cleared the npm cache by using --force on npm >=5. If that doesn't help, you'll need to open an issue with npm -- this is a bug with their package manager.

I'm sorry we can't provide more assistance.

I realize that the node_modules folder is created in another folder and not in the folder of the project

I'm not sure what you mean by this?

LeonelAV commented 6 years ago

I'm not sure what you mean by this?

i am doing create-react-app command in Desktop folder : C:\Users\leonel\Desktop: create-react-app my-app and the nodules_modules folder is not created in my-app folder, instead is created in antoher folder that i have, called Projects.

LeonelAV commented 6 years ago

I also cleared npm cache on npm 5.5.0 and still same issue.

rostun commented 6 years ago

I'm getting the same error as op (on windows 10, npm 5.5.1, and tried force clearing npm cache) :

wat2

While investigating, i also noticed that node_modules folder is "missing" because its being created at C:\node_modules and not " C:\test\my-app\node_modules as you can see below:

wat

I tried this about a month ago (on windows 10) and it worked

LeonelAV commented 6 years ago

So @rostun cleaned cache in npm 5.5.1solved the problem for you? I didn't understand how do you solved this? Thanks

gaearon commented 6 years ago

Since the issue is very recent and symptoms are similar, there has to be something that updated recently causing this.

Is there anything in common between your systems?

rostun commented 6 years ago

@gaearon with what @davidr9 mentioned, maybe its a windows only issue

since node_modules isn't being copied into the right path, maybe something changed with the way the path for that is determined

gaearon commented 6 years ago

We've been testing Windows in the past releases, and 2 days ago was the first time anyone brought it up. We haven't made a release in that timeframe. This is why I think it's some other update that's causing the issue.

If Windows support was broken for everyone we'd have known it a long time ago.

LeonelAV commented 6 years ago

well still doesn't work!! i tried with diferent versions of npm, cleaned cache and opened an issue in npm to try to solve the problem but i am not getting any answer.

LeonelAV commented 6 years ago

@rostun did you solved the problem??

gaearon commented 6 years ago

Can you link to the npm issue you filed so we can track it?

LeonelAV commented 6 years ago

https://github.com/npm/npm/issues/18981

this is link of npm issue.

gaearon commented 6 years ago

OK, this might be our bug but I don’t know where it is. I’ll need some help from somebody who can experience it.

If you run

create-react-app myapp

and then kill the process (e.g. with Ctrl+C) while it's running npm, can you describe the directory structure?

Does myapp/package.json get created? Or does package.json get created in a wrong directory (e.g. c:\)?

gaearon commented 6 years ago

The key evidence that something is wrong is here:

i am doing create-react-app command in Desktop folder : C:\Users\leonel\Desktop: create-react-app my-app and the nodules_modules folder is not created in my-app folder, instead is created in antoher folder that i have, called Projects.

and

While investigating, i also noticed that node_modules folder is "missing" because its being created at C:\node_modules and not " C:\test\my-app\node_modules as you can see below:

For two different people, node_modules is created in a different folder but it's not even always a parent folder. It sounds more like these are "initial" folders for the shell (C:\ and C:\Projects sound like something one would configure as default working directory), and for some reason npm install respects them. The question is whether package.json is in the wrong place (and then it's out fault) or if it's in the right place but npm is creating node_modules in the wrong place (and then it's an npm bug).

gaearon commented 6 years ago

It is also possible that we create package.json in the right place but then spawn npm in the wrong place. This log supports that theory:

Deleting generated file... package.json

LeonelAV commented 6 years ago

When i do create-react-app and then i kill the process the folder my-app is created in the right place, and the package.json is also created inside the my-app folder

LeonelAV commented 6 years ago

So the package.json is created in the right place, only the node_modules folder is created outside the my-app folder

Timer commented 6 years ago

Hmm, we don't set cwd but shouldn't need to: https://github.com/facebookincubator/create-react-app/blob/345f5508610a96e720b91785b49c7a934bbc477b/packages/create-react-app/createReactApp.js#L235

We change the working directory to the project folder here: https://github.com/facebookincubator/create-react-app/blob/345f5508610a96e720b91785b49c7a934bbc477b/packages/create-react-app/createReactApp.js#L162

@LeonelAV can you try editing your global CLI and explicitly setting cwd for the spawn?

gaearon commented 6 years ago

Maybe some of cross-spawn dependencies updated and broke things.

gaearon commented 6 years ago

In other words please add root as an argument to this call, this function definition, and then change this line to be:

const child = spawn(command, args, { stdio: 'inherit', cwd: root })
rostun commented 6 years ago

@LeonelAV no unfortunately I wasn't able to figure it out :/ in the interest of time i had a buddy of mine create the repo for me and am just working off of that right now (create-react-app worked on his machine)

LeonelAV commented 6 years ago

In other words please add root as an argument to this call, this function definition, and then change this line to be:

const child = spawn(command, args, { stdio: 'inherit', cwd: root })

I tried this but i'm still getting the same Error. Should i change something else or just this three lines?

gaearon commented 6 years ago

Anything unusual about shell? Are you using Cmd, PowerShell, GitBash, Cygwin, etc?

LeonelAV commented 6 years ago

I'm using Cmd.

gaearon commented 6 years ago

Can you keep the existing changes you made and also try putting

process.chdir(root);

before the spawn call?

gaearon commented 6 years ago

@LeonelAV Is there any special significance to the Projects folder on your computer? Is it the default directory you end up with when opening the shell? Is it the value of some ENV variable?

gaearon commented 6 years ago

What is the output of

reg query "HKCU\Software\Microsoft\Command Processor" /v AutoRun

on your machine?

LeonelAV commented 6 years ago

Is:

HKEY_CURRENT_USER\Software\Microsoft\Command Processor AutoRun REG_EXPAND_SZ CD/d C:\Users\leonel\Desktop\Projects

gaearon commented 6 years ago

Do you remember setting this key? 😛

I thought Projects looked suspicious (it is not special for the OS, and is not a parent directory of your projects judging by the log) so I thought maybe you tried to make your shell always start in this directory, and followed a bad tutorial that messed up your system.

I googled "how to change default terminal directory on windows" which led me to this answer with a scary "it can also really mess things up" disclaimer about the other answer.

That link led me to this blog entry describing the problem: https://blogs.msdn.microsoft.com/oldnewthing/20071121-00/?p=24433/ (it's a good blog in general btw).

Please run:

reg delete "HKLM\Software\Microsoft\Command Processor" /v AutoRun /f
reg delete "HKCU\Software\Microsoft\Command Processor" /v AutoRun /f

and then try creating an app again.

LeonelAV commented 6 years ago

It gives me:

ERROR: The system was unable to find the specified registry key or value.

gaearon commented 6 years ago

Try again, I edited the comment (my syntax was wrong).

LeonelAV commented 6 years ago

@gaearon is working now.

Should i keep this changes??? In other words please add root as an argument to this call, this function definition, and then change this line to be:

const child = spawn(command, args, { stdio: 'inherit', cwd: root })

Thanks a lot

gaearon commented 6 years ago

No, you can remove them. We'll try to figure out a better way to surface the cause of the problem though.

LeonelAV commented 6 years ago

Ok..Thank you

Timer commented 6 years ago

@gaearon you just got way too familiar with Windows internals 😆

gaearon commented 6 years ago

More than I care to know.

gaearon commented 6 years ago

https://github.com/facebookincubator/create-react-app/pull/3355

gaearon commented 6 years ago

I added a better warning for this in https://github.com/facebookincubator/create-react-app/pull/3355.

If you bump into this, the solution is described here: https://github.com/facebookincubator/create-react-app/issues/3326#issuecomment-340501321

gaearon commented 6 years ago

create-react-app@1.4.2 should now emit a readable error in this case.

ManojKSingh commented 6 years ago

I was facing the same issue,

npm cache clean --force

worked form me

chadsteele commented 6 years ago

My admin made my default Windows username "first lastname" and so, the c:\Users\first lastname\AppData... has a space in the path and causes headaches with npm, etc. I tried creating a new user with just my first name (no spaces) and everything installs fine.

sudipt1999 commented 6 years ago

Hey! I was just having the same issue as above node modules not found while i was using git bash terminal than i switched to nodejs terminal and surprisingly it work no more showing node_modules not found !!! So i would suggest to try this way around for a while until they find solution!!!1

tgifgirltechlaunch commented 6 years ago

This worked for me https://github.com/facebook/create-react-app/issues/138 Run. $ npm config set prefix /usr/local And then reinstall react. $ npm install -g create-react-app The command should work now. $ create-react-app my-app