Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
LeonelAV opened this issue Oct 25, 2017 · 51 comments
Milestone

Comments

@LeonelAV
Copy link

LeonelAV commented Oct 25, 2017

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
Copy link
Contributor

Timer commented Oct 25, 2017

Try to clear your npm cache.

@LeonelAV
Copy link
Author

I already did that and still does not work

@gaearon
Copy link
Contributor

gaearon commented Oct 25, 2017

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

@LeonelAV
Copy link
Author

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

@LeonelAV
Copy link
Author

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

@LeonelAV
Copy link
Author

LeonelAV commented Oct 26, 2017

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
Copy link

davidr9 commented Oct 26, 2017

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
Copy link
Contributor

Timer commented Oct 27, 2017

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
Copy link
Author

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
Copy link
Author

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

@rostun
Copy link

rostun commented Oct 27, 2017

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
Copy link
Author

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

@gaearon
Copy link
Contributor

gaearon commented Oct 27, 2017

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
Copy link

rostun commented Oct 27, 2017

@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
Copy link
Contributor

gaearon commented Oct 27, 2017

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
Copy link
Author

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
Copy link
Author

@rostun did you solved the problem??

@gaearon
Copy link
Contributor

gaearon commented Oct 30, 2017

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

@gaearon gaearon changed the title create-react-app does not work create-react-app fails due to node_modules being created in a wrong directory on Windows Oct 30, 2017
@LeonelAV
Copy link
Author

npm/npm#18981

this is link of npm issue.

@gaearon
Copy link
Contributor

gaearon commented Oct 30, 2017

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
Copy link
Contributor

gaearon commented Oct 30, 2017

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
Copy link
Contributor

gaearon commented Oct 30, 2017

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
Copy link
Author

LeonelAV commented Oct 30, 2017

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
Copy link
Author

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

@Timer
Copy link
Contributor

Timer commented Oct 30, 2017

@gaearon
Copy link
Contributor

gaearon commented Oct 30, 2017

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

@gaearon gaearon added this to the 1.0.15 milestone Oct 30, 2017
@gaearon
Copy link
Contributor

gaearon commented Oct 30, 2017

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
Copy link

rostun commented Oct 30, 2017

@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
Copy link
Author

LeonelAV commented Oct 30, 2017

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
Copy link
Contributor

gaearon commented Oct 30, 2017

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

@LeonelAV
Copy link
Author

I'm using Cmd.

@gaearon
Copy link
Contributor

gaearon commented Oct 30, 2017

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

process.chdir(root);

before the spawn call?

@gaearon
Copy link
Contributor

gaearon commented Oct 30, 2017

@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
Copy link
Contributor

gaearon commented Oct 30, 2017

What is the output of

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

on your machine?

@LeonelAV
Copy link
Author

Is:

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

@gaearon
Copy link
Contributor

gaearon commented Oct 30, 2017

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
Copy link
Author

It gives me:

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

@gaearon
Copy link
Contributor

gaearon commented Oct 30, 2017

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

@LeonelAV
Copy link
Author

@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
Copy link
Contributor

gaearon commented Oct 30, 2017

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

@LeonelAV
Copy link
Author

Ok..Thank you

@Timer
Copy link
Contributor

Timer commented Oct 30, 2017

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

@gaearon
Copy link
Contributor

gaearon commented Oct 30, 2017

More than I care to know.

@gaearon
Copy link
Contributor

gaearon commented Oct 30, 2017

#3355

@gaearon
Copy link
Contributor

gaearon commented Oct 30, 2017

I added a better warning for this in #3355.

If you bump into this, the solution is described here: #3326 (comment)

@gaearon gaearon closed this as completed Oct 30, 2017
@gaearon
Copy link
Contributor

gaearon commented Oct 30, 2017

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

@ManojKSingh
Copy link

I was facing the same issue,

npm cache clean --force

worked form me

@chadsteele
Copy link

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
Copy link

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
Copy link

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

@Arshaq1996
Copy link

F:\React-Lectures\Contact manger>npm install -g create-react-app
'npm' is not recognized as an internal or external command,
operable program or batch file.

when i use this command on general cmd it is workin but when i came to folder after install npm globally write the command create-react-app my-app this error is occured 'npm' is not recognized as an internal or external command,
operable program or batch file.

@lock lock bot locked and limited conversation to collaborators Jan 8, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

10 participants