Whilst addressing GitHub dependabot updates, I've been looking through the dependencies list created after running npm ls -a.
I (think I) understand the nesting involved: a pipe indicates that packages below are part of the dependencies list, and so on.
see image created from running npm ls -a > file.txt
What I don't understand is the difference between +-- and `--.
After looking at it for the best part of an hour (embarassingly) my best guess is that `-- indicates the last package in a given nesting, whilst +-- is an indication there are more packages.
It would be great if anybody could help clarify and enlighten me on what's getting output here.
Yep, it just means "the last one at this level". Depending on your locale, npm draws a nice little Unicode box drawing "end hook" thing, or the approximation you were seeing:
/tmp/example > LC_ALL=en_US.UTF-8 npm ls -a
example# /tmp/example
└─┬ string-width#5.1.2
├── eastasianwidth#0.2.0
├── emoji-regex#9.2.2
└─┬ strip-ansi#7.0.1
└── ansi-regex#6.0.1
/tmp/example > LC_ALL=C npm ls -a
example# /tmp/example
`-- string-width#5.1.2
+-- eastasianwidth#0.2.0
+-- emoji-regex#9.2.2
`-- strip-ansi#7.0.1
`-- ansi-regex#6.0.1
If you don't want to change your locale, but do want npm ls to use the better-looking glyphs, you can pass --unicode.
Related
When I run the command: npm list -g --depth=0
The following output is obtained:
output in cmd admin mode
here 2 packages are listed with +-- while another is listed as `--
what is it telling me about that package?
Here 2 packages are listed with +-- while another is listed as `--
what is it telling me about that package?
I think the +-- indicates that the package is a top-level dependency. When there is no +, just --, it is a sub-dependency of another package.
My application depends on npm packages ajv-keywords & #apideck/better-ajv-errors which in turn are dependent on package ajv but of different versions as shown in below errors.
npm ERR! peer dep missing: ajv#^6.9.1, required by ajv-keywords#3.5.2
npm ERR! peer dep missing: ajv#>=8, required by #apideck/better-ajv-errors#0.2.5
Solutions I tried with no effect -
Installed and executed npm-install-peers
Solution mentioned in https://stackoverflow.com/a/56495651/16958085
Below graph shows how the two packages are loaded -
> npm ls #apideck/better-ajv-errors#0.2.5
`-- my-app#0.1.8
`-- react-scripts#5.0.0-next.37
`-- workbox-webpack-plugin#6.2.4
`-- workbox-build#6.2.4
`-- #apideck/better-ajv-errors#0.2.5
> npm ls ajv-keywords#3.5.2
+-- babel-loader#8.2.2
| `-- schema-utils#2.7.1
| `-- ajv-keywords#3.5.2
+-- my-app#0.1.8
| `-- react-scripts#5.0.0-next.37
| `-- react-dev-utils#12.0.0-next.37
| `-- fork-ts-checker-webpack-plugin#6.0.5
| `-- schema-utils#2.7.0
| `-- ajv-keywords#3.5.2 deduped
`-- webpack#5.53.0
`-- schema-utils#3.1.1
`-- ajv-keywords#3.5.2 deduped
Please suggest an appropriate solution to satisfy both the dependencies.
that's never a fun situation to be in, and can't say either npm nor yarn have ever managed solved this completely/cleanly.
Normally, you'd be stuck waiting for your dependencies to unpin, or upgrade their versions...
That said, not sure if you have a specific requirement to use an older version of ajv-keywords, but the latest ajv-keywords uses ajv v8.
updating your package.json with
"ajv-keywords": "^5.0.0"
and re-running npm install should get you there.
If in doubt, be sure to review their readme to verify the update doesn't imply any unexpected changes for you.
How do I write a script in my Parent Folder's package.json file so that when I run npm install it installs the node modules in each folder and npm start will go to each folder and run npm start
The Frontend and Backend folder both use npm start to start up and I want to somehow do the same in the parent folder to simultaneously start both
This is the file structure:
ParentFolder
├── package.json . <--- npm install && npm start scripts
├── FrontEnd
│ ├── /node_modules
│ ├── package.json
│ └── index.js
├── Backend
│ ├── /node_modules
│ ├── package.json
│ ├── routes.js
│ └── server.js.js
Installing in two directories is easy with find
find ./*/* -maxdepth 1 -name package.json -execdir npm install \;
This looks in each directory for a package.json and executes npm install;
npm start becomes a bit harder. At least on Windows using Cygwin, I wanted to do:
npm --prefix ./FrontEnd start ./FrontEnd & npm --prefix ./Backend start ./Backend
But it wasn't actually running in the background like I expected and FrontEnd was the only one that actually started. Depending on your start script this could work for you.
Possible solutions for this could be concurrently or npm-run-all -p.
I have a package I wish to publish to NPM that also contains a demo directory like below:
.
+-- demo
| +-- src
| | +-- main.js
| +-- package.json
+-- src
| +-- main.js
+-- package.json
My question is I would like user to be able to run npm i and npm start to start up the development server but I don't know how to run npm i in the demo directory at the same time as the top level one. Using "postinstall": "cd demo && npm i" puts me in an infinite loop of installs.
EDIT1:
My demo package.json depends on the parent module using "parent-module": "file:../". I believe this is the cause but how can i solve it. I don't want to use a custom npm install command.
EDIT2:
Even with the parent dependency removed, it still attempts to go into an infinite loop but it now errors as the nested demo folders are not there anymore.
Running npm install in a postinstall script will not work because this means that the postinstall script recursively calls itself: postinstall calls install, which in turn triggers postinstall (and so on forever) as defined in the npm script lifecycle rules.
For anyone still looking for this, you can add this script in the root package.json:
"scripts": {
"postinstall": "npm install --ignore-scripts -C ./demo"
the --ignore-scripts option will prevent this from running recursively
The latest version of jHipster gives different options than the one being displayed in my command prompt. I am wondering why am I missing some things like the oracle database option?
Does anyone have any ideas? Doing npm list generator-jhipster shows that I in fact DO have the current latest version.
This is what I should see:
What I should see
Versus what I actually see:
https://twitter.com/BuilderDeviser/status/694251531261050882
Doing an npm list -g --depth=0 :
C:\Program Files\nodejs
+-- bower#1.7.7
+-- capslink#0.0.0
+-- generator-jhipster#2.27.0
+-- grunt-cli#0.1.13
+-- gulp#3.9.0
+-- npm#3.6.0
+-- reinstall#1.1.0
+-- semver#5.1.0
+-- strongloop#6.0.0
`-- yo#1.6.0
Found the problem.... i did a drive search for 'generator-jhipster' and windows found all folders of that name.
I looked at each path and found that generator-jhipster way back from 2.7 was still hanging around in zip format. I definitely don't need that anymore. I ended up trashing any old instances of generator-jhipster and any cache/temp locations.
I reinstalled forcing npm to target 2.27 by doing 'npm install -g generator-jhipster#2.27'
Now I have the current and latest version of jhipster runnning!