I develop my app by using npm workspace.but I am totally novice to this concept so that I would like to understand npm workspace behavior
.
├── package.json
└── packages
├── a
│ └── package.json
├── b
│ └── package.json
└── c
└── package.json
package.json
{
"workspaces": [
"packages/*"
]
}
My question is
①what happens when I run npm install in root directory ?
All the packages are installed in each repository ? or root directory ?
②npm install in each project is not recommended ?
if someone has opinion, will you please let me know.
Thanks
So long as all packages have the same version of dependencies listed (e.g. thing#1.0.0), then npm install run from the root of your repository will add the dependency into the root node_modules directory.
If one of your packages (e.g. packages/c) has a different version of a dependency (e.g. thing#1.0.1) then that would appear in packages/2/node_modules)
In theory you are using npm workspaces to ensure some consistency across packages, therefore ensuring your versions are consistent will mean node_modules is only ever created in the root of your repository
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 would like to organise a flutter project into a multi-package one with following requirements:
use one repository for this project
able for developers to work on the packages in this repository locally
make the packages accessible as dependencies from other projects outside of this repository
The file setup for the repository I have now is:
.
├── app_base
│ ├── ...
│ └── pubspec.yaml
├── feature
│ ├── ...
│ └── pubspec.yaml
└── README.md
I tried using path dependencies like this in app_base/pubspec.yaml:
name: app_base
dependencies:
feature:
path: ../feature
and it works for local development but if I try to use app_base in a completely different project and not use paths but a git dependency:
name: actual_app
dependencies:
app_base:
git:
url: ssh://address.to/the_repo.git
path: app_base
ref: deadbaca
it cannot resolve the transitive feature dependency:
Running "flutter packages get" in actual_app...
Error on line 21, column 11: Invalid description: "../feature" is a relative path, but this isn't a local pubspec.
path: ../feature
^^^^^^^^^^
pub get failed (65)
Process finished with exit code 65
Is there a way to make it work for both local development and used as a git dependency from other project?
Just use Git dependencies for both scenarios (locally and for other projects).
If you think this is cumbersome during local development, use path dependencies locally and change it back to Git before committing.
I get an issue when setting up PhantomJS on Ubuntu 14.04, I used NPM to install it but it doesn't work and the installation is stopped at "70%"...
Command : sudo npm install phantomjs --save
> phantomjs#1.9.17 install /var/www/gestiaweb/GestionDettes.3000/node_modules/phantomjs
> node install.js
Downloading https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-1.9.8-linux-x86_64.tar.bz2
Saving to /var/www/gestiaweb/GestionDettes.3000/node_modules/phantomjs/phantomjs/phantomjs-1.9.8-linux-x86_64.tar.bz2
Receiving...
[============================------------] 70% 0.0s
Received 12854K total.
Extracting tar contents (via spawned process)
Removing /var/www/gestiaweb/GestionDettes.3000/node_modules/phantomjs/lib/phantom
Copying extracted folder /var/www/gestiaweb/GestionDettes.3000/node_modules/phantomjs/phantomjs/phantomjs-1.9.8-linux-x86_64.tar.bz2-extract-1435657830806/phantomjs-1.9.8-linux-x86_64 -> /var/www/gestiaweb/GestionDettes.3000/node_modules/phantomjs/lib/phantom
Writing location.js file
Done. Phantomjs binary available at /var/www/gestiaweb/GestionDettes.3000/node_modules/phantomjs/lib/phantom/bin/phantomjs
phantomjs#1.9.17 node_modules/phantomjs
├── which#1.0.9
├── progress#1.1.8
├── kew#0.4.0
├── request-progress#0.3.1 (throttleit#0.0.2)
├── adm-zip#0.4.4
├── npmconf#2.1.1 (ini#1.3.4, uid-number#0.0.5, inherits#2.0.1, once#1.3.2, osenv#0.1.3, config-chain#1.1.9, nopt#3.0.3, semver#4.3.6, mkdirp#0.5.1)
└── request#2.42.0 (caseless#0.6.0, forever-agent#0.5.2, aws-sign2#0.5.0, stringstream#0.0.4, oauth-sign#0.4.0, tunnel-agent#0.4.0, json-stringify-safe#5.0.1, qs#1.2.2, node-uuid#1.4.3, mime-types#1.0.2, form-data#0.1.4, bl#0.9.4, http-signature#0.10.1, tough-cookie#2.0.0, hawk#1.1.1)
icecom#web-test:/var/www/gestiaweb/GestionDettes.3000$
Put the executable into a directory that is in PATH (or put a symlink into PATH) or let NPM install it globally:
npm -g install phantomjs
I'm on Yosemite, with Homebrew, Node and NPM installed.
Homebrew 0.9.5
Node v0.12.3
NPM 2.9.1
For whatever reason, I can't get Yeoman to properly install. The install seems to go fine, no errors, but when I check to confirm the install it wont give me the --version, nor can I execute the yo function...
Gregs-MacBook-Pro:~ G$ npm install -g yo
/Users/G/npm/bin/yo -> /Users/G/npm/lib/node_modules/yo/lib/cli.js
> yo#1.4.6 postinstall /Users/G/npm/lib/node_modules/yo
> yodoctor
Yeoman Doctor
Running sanity checks on your system
✔ Global configuration file is valid
✔ No .bowerrc file in home directory
✔ No .yo-rc.json file in home directory
✔ NODE_PATH matches the npm root
Everything looks all right!
yo#1.4.6 /Users/G/npm/lib/node_modules/yo
├── titleize#1.0.0
├── array-uniq#1.0.2
├── figures#1.3.5
├── user-home#1.1.1
├── opn#1.0.2
├── async#0.9.2
├── humanize-string#1.0.1 (decamelize#1.0.0)
├── sort-on#1.2.0 (dot-prop#2.0.0)
├── yeoman-character#1.0.1 (supports-color#1.3.1)
├── string-length#1.0.0 (strip-ansi#2.0.1)
├── cross-spawn#0.2.9 (lru-cache#2.6.4)
├── findup#0.1.5 (commander#2.1.0, colors#0.6.2)
├── chalk#1.0.0 (escape-string-regexp#1.0.3, ansi-styles#2.0.1, supports-color#1.3.1, strip-ansi#2.0.1, has-ansi#1.0.3)
├── yosay#1.0.4 (ansi-regex#1.1.1, ansi-styles#2.0.1, word-wrap#1.0.3, strip-ansi#2.0.1, pad-component#0.0.1, taketalk#1.0.0, minimist#1.1.1)
├── root-check#1.0.0 (sudo-block#1.2.0, downgrade-root#1.1.0)
├── update-notifier#0.3.2 (is-npm#1.0.0, latest-version#1.0.0, semver-diff#2.0.0)
├── package-json#1.1.0 (registry-url#3.0.3)
├── npm-keyword#1.1.1 (registry-url#3.0.3)
├── meow#3.1.0 (object-assign#2.0.0, minimist#1.1.1, camelcase-keys#1.0.0, indent-string#1.2.1)
├── got#2.9.2 (lowercase-keys#1.0.0, object-assign#2.0.0, timed-out#2.0.0, is-stream#1.0.1, prepend-http#1.0.1, nested-error-stacks#1.0.0, statuses#1.2.1, infinity-agent#2.0.3, read-all-stream#2.1.2, duplexify#3.4.0)
├── fullname#1.1.0 (npmconf#2.1.2)
├── yeoman-environment#1.2.5 (escape-string-regexp#1.0.3, log-symbols#1.0.2, untildify#2.0.0, diff#1.4.0, text-table#0.2.0, debug#2.2.0, mem-fs#1.1.0, grouped-queue#0.3.0, globby#1.2.0)
├── configstore#0.3.2 (object-assign#2.0.0, xdg-basedir#1.0.1, osenv#0.1.1, graceful-fs#3.0.7, uuid#2.0.1, mkdirp#0.5.1, js-yaml#3.3.1)
├── lodash#3.9.2
├── insight#0.5.3 (object-assign#2.0.0, lodash.debounce#3.1.0, os-name#1.0.3, tough-cookie#0.12.1, request#2.55.0)
├── yeoman-doctor#1.3.2 (object-values#1.0.0, log-symbols#1.0.2, each-async#1.1.1, twig#0.7.2)
└── inquirer#0.8.5 (ansi-regex#1.1.1, cli-width#1.0.1, through#2.3.7, readline2#0.1.1, rx#2.5.2)
Gregs-MacBook-Pro:~ G$ yo -v
-bash: yo: command not found
I've opened the .bashrc (have to use sudo to be able to open + save it). Without sudo I can't save the changes.
sudo nano /.bashrc
The bashrc file reads:
# NPM packages in homedir
NPM_PACKAGES="$HOME/.npm-packages"
# Tell our environment about user-installed node tools
PATH="$NPM_PACKAGES/bin:$PATH"
# Unset manpath so we can inherit from /etc/manpath via the `manpath` command
unset MANPATH # delete if you already modified MANPATH elsewhere in your configuration
MANPATH="$NPM_PACKAGES/share/man:$(manpath)"
# Tell Node about these packages
NODE_PATH="$NPM_PACKAGES/lib/node_modules:$NODE_PATH"
I've tried installing Node thru Homebrew first and found out about this issue which I couldnt resolve either. https://gist.github.com/DanHerbert/9520689
Since that didn't I blew everything away in terminal, including node, npm, and homebrew.
Now I'm stuck, npm lets me install packages grunt-cli, bower, and yeoman, but any time I try calling those packages I get:
-bash: yo: command not found
I'm assuming it has something to do with the /.bashrc contents, somebody help :(
I had the same problem under Yosemite.
My solution was:
sudo find /usr/local/ -name yo
/usr/local//Cellar/node/4.2.1/libexec/npm/bin/yo
open $HOME/.profile
export NODE_PATH="/usr/local/lib/node_modules"
export PATH="/usr/local/Cellar/node/4.2.1/libexec/npm/bin:$PATH"
export NODE_PATH=$NODE_PATH:/usr/local/Cellar/node/4.2.1/libexec/npm/lib/node_modules
open new terminal:
yo --version
1.4.8
perhaps your node version is a problem. At beginning after install 'brew install node' I had too
node --version
v0.12.7
After
brew update
and reinstall node
node --version
v4.2.1