npm cant find package.json when installing react - node.js

This is a followup question to my earlier question (but is an independent question)
I am trying to install react and react-dom on a Mac:
npm install --save react react-dom
but get the following warnings (path names replaced with ...):
npm WARN saveError ENOENT: no such file or directory, open '/Users/../Z/package.json'
/Users/.../Z
├─┬ react#15.4.1
│ ├─┬ fbjs#0.8.8
│ │ ├── core-js#1.2.7
│ │ ├─┬ isomorphic-fetch#2.2.1
│ │ │ ├─┬ node-fetch#1.6.3
│ │ │ │ ├─┬ encoding#0.1.12
│ │ │ │ │ └── iconv-lite#0.4.15
│ │ │ │ └── is-stream#1.1.0
│ │ │ └── whatwg-fetch#2.0.1
│ │ ├─┬ promise#7.1.1
│ │ │ └── asap#2.0.5
│ │ ├── setimmediate#1.0.5
│ │ └── ua-parser-js#0.7.12
│ ├─┬ loose-envify#1.3.0
│ │ └── js-tokens#2.0.0
│ └── object-assign#4.1.0
└── react-dom#15.4.1
npm WARN enoent ENOENT: no such file or directory, open '/Users/.../Z/package.json'
npm WARN Z No description
npm WARN Z No repository field.
npm WARN Z No README data
npm WARN Z No license field.
I searched around a bit but did not find a good reason for these warnings. SO posts like these seem to suggest installing react in the same directory where node modules are installed. My node is installed in usr/local/bin but package.json does not appear anywhere on the machine even on a global search. I just installed npm before trying to install react so don't think its a versioning issue.

If this is a brand new project, it can be resolved by running npm init from the root directory of your project (where you want package.json to be created), and press "ENTER" at all of the prompts to accept the default answers. (It is easy to change your responses by directly modifying the package.json file later.)
Once the package.json has been created, you will be able to run npm install commands!

Actually for me it just worked like this :
I ran npx create-react-app "nameOfProject" , if you type npm start in the same folder it won't work because it tries to find the package.json in the same folder , when your package.json is in the subfolder ( the folder of the "nameOfProject" ).
Run cd "nameOfProject" to change the directory and them run npm start .

Check the folder you're in. Usually after using npx create-react-app, you'll be in the same folder. you will be needed to cd into the new folder that is created after running above command. there you'll find package.json.

Related

How to resolve npm vulnerability with npm as the dependent package involved?

So I run npm audit and all of the vulnerabilities are due to some dependency in npm, particularly node-gyp which is using a vulnerable version of tar. Note that I don’t have node-gyp in my package.json.
┌───────────────┬──────────────────────────────────────────────────────────────┐
│ High │ Arbitrary File Overwrite │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Package │ tar │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Patched in │ >=2.2.2 <3.0.0 || >=4.4.2 │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Dependency of │ npm │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Path │ npm > npm-lifecycle > node-gyp > tar │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ More info │ https://npmjs.com/advisories/803 │
└───────────────┴──────────────────────────────────────────────────────────────┘
I tried updating to the latest version of npm but I still get the same audit report. It’s quite nested. How do I resolve this?

AWS EB deployment issue "Failed to run npm install"

I'm trying to deploy a Node.js app to EB. The problem is, I'm getting the error on my EB dashboard, "Update environment operation is complete, but with errors.", and my app isn't running.
So I fetched the error log for my instance:
i-0d5cffacd74ddf4dc Severe 5 hours 2 - - - - - - - - - - 0.00 0.00 0.0 0.0 100 0.0
Application deployment failed at 2017-11-26T17:43:27Z with exit status 1 and error: Hook /opt/elasticbeanstalk/hooks/appdeploy/pre/50npm.sh failed.
+ /opt/elasticbeanstalk/containerfiles/ebnode.py --action npm-install
npm WARN lifecycle node#9.2.0~preinstall: cannot run in wd %s %s (wd=%s) node#9.2.0 node installArchSpecificPackage /tmp/deployment/application/node_modules/.staging/node-2356d873
Portfolio#0.0.1 /tmp/deployment/application
├─┬ body-parser#1.18.2
│ ├── bytes#3.0.0
│ ├── content-type#1.0.4
│ ├─┬ debug#2.6.9
│ │ └── ms#2.0.0
│ ├── depd#1.1.1
│ ├─┬ http-errors#1.6.2
│ │ ├── inherits#2.0.3
│ │ ├── setprototypeof#1.0.3
│ │ └── statuses#1.4.0
│ ├── iconv-lite#0.4.19
│ ├─┬ on-finished#2.3.0
│ │ └── ee-first#1.1.1
│ ├── qs#6.5.1
│ ├─┬ raw-body#2.3.2
│ │ └── unpipe#1.0.0
│ └─┬ type-is#1.6.15
│ ├── media-typer#0.3.0
│ └─┬ mime-types#2.1.17
│ └── mime-db#1.30.0
├─┬ express#4.16.2
│ ├─┬ accepts#1.3.4
│ │ └── negotiator#0.6.1
│ ├── array-flatten#1.1.1
│ ├── content-disposition#0.5.2
│ ├── cookie#0.3.1
│ ├── cookie-signature#1.0.6
│ ├── encodeurl#1.0.1
│ ├── escape-html#1.0.3
│ ├── etag#1.8.1
│ ├─┬ finalhandler#1.1.0
│ │ └── statuses#1.3.1
│ ├── fresh#0.5.2
│ ├── merge-descriptors#1.0.1
│ ├── methods#1.1.2
│ ├── parseurl#1.3.2
│ ├── path-to-regexp#0.1.7
│ ├─┬ proxy-addr#2.0.2
│ │ ├── forwarded#0.1.2
│ │ └── ipaddr.js#1.5.2
│ ├── range-parser#1.2.0
│ ├── safe-buffer#5.1.1
│ ├─┬ send#0.16.1
│ │ ├── destroy#1.0.4
│ │ ├── mime#1.4.1
│ │ └── statuses#1.3.1
│ ├── serve-static#1.13.1
│ ├── setprototypeof#1.1.0
│ ├── statuses#1.3.1
│ ├── utils-merge#1.0.1
│ └── vary#1.1.2
└── nodemailer#4.4.0
npm ERR! Linux 4.9.58-18.55.amzn1.x86_64
npm ERR! argv "/opt/elasticbeanstalk/node-install/node-v6.11.5-linux-x64/bin/node" "/opt/elasticbeanstalk/node-install/node-v6.11.5-linux-x64/bin/npm" "--production" "install"
npm ERR! node v6.11.5
npm ERR! npm v3.10.10
npm ERR! path /tmp/deployment/application/node_modules/node/bin/node
npm ERR! code ENOENT
npm ERR! errno -2
npm ERR! syscall chmod
npm ERR! enoent ENOENT: no such file or directory, chmod '/tmp/deployment/application/node_modules/node/bin/node'
npm ERR! enoent ENOENT: no such file or directory, chmod '/tmp/deployment/application/node_modules/node/bin/node'
npm ERR! enoent This is most likely not a problem with npm itself
npm ERR! enoent and is related to npm not being able to find a file.
npm ERR! enoent
npm ERR! Please include the following file with any support request:
npm ERR! /tmp/deployment/application/npm-debug.log
Running npm install: /opt/elasticbeanstalk/node-install/node-v6.11.5-linux-x64/bin/npm
Setting npm config jobs to 1
npm config jobs set to 1
Running npm with --production flag
Failed to run npm install. Snapshot logs for more details.
Traceback (most recent call last):
File "/opt/elasticbeanstalk/containerfiles/ebnode.py", line 695, in <module>
main()
File "/opt/elasticbeanstalk/containerfiles/ebnode.py", line 677, in main
node_version_manager.run_npm_install(options.app_path)
File "/opt/elasticbeanstalk/containerfiles/ebnode.py", line 136, in run_npm_install
self.npm_install(bin_path, self.config_manager.get_container_config('app_staging_dir'))
File "/opt/elasticbeanstalk/containerfiles/ebnode.py", line 180, in npm_install
raise e
subprocess.CalledProcessError: Command '['/opt/elasticbeanstalk/node-install/node-v6.11.5-linux-x64/bin/npm', '--production', 'install']' returned non-zero exit status 254.
Incorrect application version "Deploy5" (deployment 2). Expected version "Deploy06" (deployment 3).
In the midst of it all, I find Failed to run npm install. Snapshot logs for more details. Why does this happen? My app runs perfectly fine locally - why can't it run on aws?
File structure:
.zip
node_modules/
public/
app.js
package.json

How does npm list know which ones are direct dependencies?

Get into a new directly, after typing those three commands:
npm install underscore
npm install lodash
npm install express
I get a node_modules directory with many packages:
$ ls node_modules
accepts cookie-signature encodeurl forwarded lodash mime-db parseurl send underscore
array-flatten debug escape-html fresh media-typer mime-types path-to-regexp serve-static unpipe
content-disposition depd etag http-errors merge-descriptors ms proxy-addr setprototypeof utils-merge
content-type destroy express inherits methods negotiator qs statuses vary
cookie ee-first finalhandler ipaddr.js mime on-finished range-parser type-is
While using npm list, I can get a tree strcture:
$ npm list
/tmp/play/npm
├─┬ express#4.14.0
│ ├─┬ accepts#1.3.3
│ │ ├─┬ mime-types#2.1.13
│ │ │ └── mime-db#1.25.0
│ │ └── negotiator#0.6.1
│ ├── array-flatten#1.1.1
│ ├── content-disposition#0.5.1
│ ├── content-type#1.0.2
│ ├── cookie#0.3.1
│ ├── cookie-signature#1.0.6
│ ├─┬ debug#2.2.0
│ │ └── ms#0.7.1
│ ├── depd#1.1.0
│ ├── encodeurl#1.0.1
│ ├── escape-html#1.0.3
│ ├── etag#1.7.0
│ ├─┬ finalhandler#0.5.0
│ │ ├── statuses#1.3.1
│ │ └── unpipe#1.0.0
│ ├── fresh#0.3.0
│ ├── merge-descriptors#1.0.1
│ ├── methods#1.1.2
│ ├─┬ on-finished#2.3.0
│ │ └── ee-first#1.1.1
│ ├── parseurl#1.3.1
│ ├── path-to-regexp#0.1.7
│ ├─┬ proxy-addr#1.1.2
│ │ ├── forwarded#0.1.0
│ │ └── ipaddr.js#1.1.1
│ ├── qs#6.2.0
│ ├── range-parser#1.2.0
│ ├─┬ send#0.14.1
│ │ ├── destroy#1.0.4
│ │ ├─┬ http-errors#1.5.1
│ │ │ ├── inherits#2.0.3
│ │ │ └── setprototypeof#1.0.2
│ │ └── mime#1.3.4
│ ├── serve-static#1.11.1
│ ├─┬ type-is#1.6.14
│ │ └── media-typer#0.3.0
│ ├── utils-merge#1.0.0
│ └── vary#1.1.0
├── lodash#4.17.2
└── underscore#1.8.3
My question is: from all those dependencies, how does npm list know which ones are my direct dependencies such as undersocre, lodash and express?
note: I don't have a package.json file.
It builds the list on the basis of the dependencies of the modules. The dependencies of the modules are specified in the package.json of each module in the dependencies field. When you install a module npm adds some additional fields to the module's package.json and one of those is the field _requiredBy to store the dependency link in the other direction as well. If you run the npm list command it goes through all the modules and reads the _requiredBy field in package.json of each module.
If you install a module directly without saving it to your package.json, npm adds #USER to the _requiredBy field to signify that you manually installed it and it is not just a dependency of the other modules. Then npm list shows that module in the root of the tree as well.
You can use this command:
npm list --depth=0 2>/dev/null
npm list command will print to stdout all the versions of packages that are installed, as well as their dependencies, in a tree-structure.
So you have only installed three packages
npm install underscore
npm install lodash
npm install express
All other packages are dependency for express package

Installing Cycle.js and running examples: enoent package.json file is missing

I don't have too much experience in NodeJs. I wanted to try Cyclejs. The documentation says:
Create a new directory and run this inside that directory:
npm install rx #cycle/core #cycle/dom
When I do this, I get the following warning:
➜ cycle-examples npm install rx #cycle/core #cycle/dom
/Users/mertnuhoglu/projects/js/tmp2/cycle-examples
├── #cycle/core#5.0.1
├─┬ #cycle/dom#7.1.1
│ ├─┬ es6-map#0.1.1
│ │ ├── d#0.1.1
│ │ ├─┬ es5-ext#0.10.8
│ │ │ ├── es6-iterator#2.0.0
│ │ │ └── es6-symbol#3.0.1
│ │ ├─┬ es6-iterator#0.1.3
│ │ │ └── es6-symbol#2.0.1
│ │ ├─┬ es6-set#0.1.2
│ │ │ ├── es6-iterator#2.0.0
│ │ │ └── es6-symbol#3.0.1
│ │ ├── es6-symbol#0.1.1
│ │ └── event-emitter#0.3.4
│ ├── matches-selector#1.0.0
│ ├── vdom-parser#1.2.1
│ ├─┬ vdom-to-html#2.1.1
│ │ ├── escape-html#1.0.3
│ │ ├─┬ param-case#1.1.1
│ │ │ └─┬ sentence-case#1.1.2
│ │ │ └── lower-case#1.1.2
│ │ └── xtend#4.0.0
│ ├─┬ virtual-dom#2.1.1
│ │ ├── browser-split#0.0.1
│ │ ├─┬ error#4.4.0
│ │ │ ├── camelize#1.0.0
│ │ │ └── string-template#0.2.1
│ │ ├─┬ ev-store#7.0.0
│ │ │ └── individual#3.0.0
│ │ ├─┬ global#4.3.0
│ │ │ ├─┬ min-document#2.17.0
│ │ │ │ └── dom-walk#0.1.1
│ │ │ └── process#0.5.2
│ │ ├── is-object#1.0.1
│ │ ├── next-tick#0.2.2
│ │ └── x-is-string#0.1.0
│ └── x-is-array#0.1.0
└── rx#4.0.6
npm WARN ENOENT ENOENT, open '/Users/mertnuhoglu/projects/js/tmp2/cycle-examples/package.json'
npm WARN EPACKAGEJSON cycle-examples No description
npm WARN EPACKAGEJSON cycle-examples No repository field.
npm WARN EPACKAGEJSON cycle-examples No README data
npm WARN EPACKAGEJSON cycle-examples No license field.
After that I cloned cycle-examples and run npm start following the instructions. I get the following error:
➜ cycle-examples git clone https://github.com/cyclejs/cycle-examples
Cloning into 'cycle-examples'...
remote: Counting objects: 184, done.
remote: Total 184 (delta 0), reused 0 (delta 0), pack-reused 184
Receiving objects: 100% (184/184), 31.08 KiB | 0 bytes/s, done.
Resolving deltas: 100% (72/72), done.
Checking connectivity... done.
➜ cycle-examples npm start
npm ERR! Darwin 14.0.0
npm ERR! argv "node" "/usr/local/bin/npm" "start"
npm ERR! node v0.12.7
npm ERR! npm v3.3.8
npm ERR! path /Users/mertnuhoglu/projects/js/tmp2/cycle-examples/package.json
npm ERR! code ENOENT
npm ERR! errno -2
npm ERR! enoent ENOENT, open '/Users/mertnuhoglu/projects/js/tmp2/cycle-examples/package.json'
npm ERR! enoent This is most likely not a problem with npm itself
npm ERR! enoent and is related to npm not being able to find a file.
npm ERR! enoent
npm ERR! Please include the following file with any support request:
npm ERR! /Users/mertnuhoglu/projects/js/tmp2/cycle-examples/npm-debug.log
The error says I need to have package.json. The git repository does not have it. Should I create it on my own? If so, what should I put inside that file?
npm version is 3.3.8
I have browserify#11.2.0 and babel#5.8.23 libraries installed globally in Node.
The cycle-examples is a collection of examples. You need to enter an actual example directory, e.g., bmi-nested, and from there issue npm start.

Cannot Install gulp-sass

I'm trying to learn how to use gulp / sass / and all the other fun tools with Nodejs and I'm having an issue installing gulp-sass. The process I'm using to install everything is:
1. Start Git Bash in the project folder
2. npm init
3. npm install gulp -g
4. npm install gulp --save-dev
5. npm install gulp-sass <- this is where I get errors
Once I get to step five, I get the following error:
$ npm install gulp-sass
npm WARN package.json project#1.0.0 No repository field.
npm WARN package.json project#1.0.0 No README data
-
> node-sass#3.2.0 install \\primary\home\mendsley\profile\Desktop\project\node_modules\gulp- sass\node_modules\node-sass
> node scripts/install.js
'\\primary\home\mendsley\profile\Desktop\project\node_modules\gulp- sass\node_modules\node-sass'
CMD.EXE was started with the above path as the current directory.
UNC paths are not supported. Defaulting to Windows directory.
module.js:338
throw err;
^
Error: Cannot find module 'C:\Windows\scripts\install.js'
at Function.Module._resolveFilename (module.js:336:15)
at Function.Module._load (module.js:278:25)
at Function.Module.runMain (module.js:501:10)
at startup (node.js:129:16)
at node.js:814:3
npm ERR! Windows_NT 6.1.7601
npm ERR! argv "c:\\Program Files\\nodejs\\node.exe" "c:\\Users\\mendsley\\AppData\\Roaming\\npm\\node_modules\\npm\\bin\\npm-cli.js" "install" "gulp-sass"
npm ERR! node v0.12.1
npm ERR! npm v2.13.1
npm ERR! code ELIFECYCLE
npm ERR! node-sass#3.2.0 install: `node scripts/install.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the node-sass#3.2.0 install script 'node scripts/install.js'.
npm ERR! This is most likely a problem with the node-sass package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! node scripts/install.js
npm ERR! You can get their info via:
npm ERR! npm owner ls node-sass
npm ERR! There is likely additional logging output above.
npm ERR! Please include the following file with any support request:
npm ERR! \\primary\home\mendsley\profile\Desktop\project\npm-debug.log
I'm trying this on my work computer, so I'm not sure if that matters. The system admin says there should not be any issue and other people have no issue with same package...and talking to them, they offer no help. I tried everything on my personal laptop and gulp-sass installs just fine, so it is something with my work pc.
My initial thought is it's a path issue, but then why do other packages install okay?
I did uninstall/reinstall Nodejs, but that didn't help.
Does anyone have an idea?
Thanks in advance!
Your first guess was good as it is a matter of path name. From the error message :
UNC paths are not supported. Defaulting to Windows directory.
Npm needed to access \\primary\home\mendsley\...\node_modules\node-sass so as to execute the gulp-sass installation script. But this path is a UNC path (Uniform Naming Convention) and therefore is not supported.
As a consequence, the npm command defaulted to C:/Windows instead and tries to execute the installation script of gulp-sass (install.js) but this script is, as you might guess, not present in this directory.
It could be a dependency hell problem with an older NodeJS or NPM version, too. gulp-sass depends on node-sass, which in turn depends on other packages, and they also depend on the right NodeJS and NPM version. For version 0.7.3 the full dependencies look like this:
├─┬ gulp-sass#0.7.3
│ ├── map-stream#0.1.0
│ └─┬ node-sass#0.9.6
│ ├─┬ chalk#0.5.1
│ │ ├── ansi-styles#1.1.0
│ │ ├── escape-string-regexp#1.0.3
│ │ ├─┬ has-ansi#0.1.0
│ │ │ └── ansi-regex#0.2.1
│ │ ├─┬ strip-ansi#0.3.0
│ │ │ └── ansi-regex#0.2.1
│ │ └── supports-color#0.2.0
│ ├── get-stdin#3.0.2
│ ├─┬ mkdirp#0.5.1
│ │ └── minimist#0.0.8
│ ├─┬ mocha#1.21.5
│ │ ├── commander#2.3.0
│ │ ├─┬ debug#2.0.0
│ │ │ └── ms#0.6.2
│ │ ├── diff#1.0.8
│ │ ├── escape-string-regexp#1.0.2
│ │ ├─┬ glob#3.2.3
│ │ │ ├── graceful-fs#2.0.3
│ │ │ ├── inherits#2.0.1
│ │ │ └─┬ minimatch#0.2.14
│ │ │ ├── lru-cache#2.7.3
│ │ │ └── sigmund#1.0.1
│ │ ├── growl#1.8.1
│ │ ├─┬ jade#0.26.3
│ │ │ ├── commander#0.6.1
│ │ │ └── mkdirp#0.3.0
│ │ └─┬ mkdirp#0.5.0
│ │ └── minimist#0.0.8
│ ├── nan#1.3.0
│ ├── node-sass-middleware#0.3.1
│ ├── node-watch#0.3.5
│ ├── object-assign#1.0.0
│ ├─┬ sinon#1.10.3
│ │ ├─┬ formatio#1.0.2
│ │ │ └── samsam#1.1.3
│ │ └─┬ util#0.10.3
│ │ └── inherits#2.0.1
│ └── yargs#1.3.3
I had trouble to install version 0.7.3 of gulp-sass with the latest versions of NodeJS 5.2.0 and NPM 3.5.2. This older version of gulp-sass worked only with the older version of NodeJS 0.12.9 and NPM 2.14.9, see also https://github.com/sass/node-sass/issues/1166
Look at this:
"CMD.EXE was started with the above path as the current directory.
UNC paths are not supported. Defaulting to Windows directory."
You can use the pushd command. As example for --global Installation for a domain user on network share:
pushd \\server\yourpath\user\AppData\Roaming\npm
hint: you could figure out the right path for global npm installations by using %appdata%\npm in your Explorer, the cmd answers:
Z:\user\AppData\Roaming\npm>
now you can type "npm install node-sass" (or gulp-sass or whatever)
Z:\user\AppData\Roaming\npm>npm install node-sass
without --global or -g, in this path you are "global"
if finished, then popd to disconnect the Z:
I had the same issue and I fixed it with simple step.
The real problem is with autorun to set the path of your command prompt. It is related to your registry.
i just deleted the autorun file in registry for command processor and it started working normally.
Hop in this link

Resources