npm install - how to trigger npm task as a post-install hook? - scripting

After npm install is run I would like to run
npm run jspm install
I have package.json
"scripts": {
"postinstall" : "npm run jspm install",
"jspm": "jspm"
},
This throws an error since npm run jspm install gets passed to node rather than npm. What's the correct way to do this?

There doesn't seem to be a reason to reference the jspm script. You can refer to jspm directly in the postinstall script:
"postinstall" : "jspm install",

Related

package.json disable "npm install"

Is there any way to disable the command npm install or npm i on a project through the package.json config?
I'm using yarn to add and install npm dependencies, and I want to force to not use npm install

npm install command not working in npm script

Given a package.json that includes the following scripts:
"scripts": {
"dev": "npm install && webpack-dev-server --hot --progress --colors",
"build": "npm install && webpack --env.prod --progress --colors",
"start": "npm run dev"
}
Running npm start gives me many errors of the sort
`npm WARN tar ENOENT: no such file or directory, open 'C:\repos\my-project\node_modules\.staging\core-js-ea8988d1\client\shim.js'
followed by
npm ERR! code 1
npm ERR! Command failed: git submodule update -q --init --recursive
npm ERR! C:/Users/JohnDoe/AppData/Local/Programs/Git/mingw64/libexec/git-core\git-submodule: line 21: .: git-sh-setup: file not found
However, if instead I just run npm install directly, the npm installation of packages succeeds with no errors, and then I can run npm start thereafter with no issues. Why is this? There seems to be some kind of issue with including npm install in an npm script if the packages are not yet installed. I also tried setting start to "npm install" but running npm start gave me the same errors in that case.

Babel doesn't run from npm script

I have the babel cli installed on my machine using:
npm install -g babel-cli
When I run this command I get the desired output. i.e out.js is created
babel script.js --out-file out.js
but when I try to run that command via npm I get an error saying
The CLI has been moved into the package `babel-cli`.
$ npm install -g babel-cli
Here's the package.json:
{
"name": "youtubeapiloader",
"version": "1.0.0",
"main": "index.js",
"scripts": {
"compile": "babel -g src/youtube-api-loader.js --out-file youtube-api.js",
"prepublish": "npm run compile"
},
"devDependencies": {
"babel": "^6.1.18"
}
}
Have you tried installing babel-cli as a devDependency already?
I managed to get it working like this. Just do
npm install babel-cli --save-dev
Perhaps you might also need babel-core, but I can not remember correctly.
Note that if you want to run this using Travis CI you might still need to globally install babel-cli using a custom installation step within your .travis.yml. e.g.
language: node_js
sudo: false
node_js:
- "5.0"
install:
- npm install -g babel-cli
- npm install

How to install bower dependencies using npm install?

I want npm install to install the bower dependencies as well. I have a bower.json file containing frontend packages and there is package.json file which contains the backend packages. After i run npm install, node_modules are installed whereas the dependencies mentioned in bower.json file are not installed.
I don't want to use bower install rather I want to do all this with npm install command.
It's quite simple. If you have bower listed in package.json as dependency you may add postinstall script to your package.json as follows:
"scripts": {
"postinstall": "bower install"
}
and running npm install will launch also bower install automatically

How do I install bower using package.json and npm install?

How do I install bower using package.json and npm?
I have my package.json file setup like so..
{
"name": "myprogramname",
"version": "0.0.1",
"devDependencies": {
"bower": "1.2.6"
//other dependencies are listed as well
}
}
from the command line I run
npm install
It installs all of my dependencies in devDependencies except bower. Any reason for this?
Also,
which bower
returns nothing
Npm did actually install Bower but not globally. If you check your node_modules/ directory, it should be there.
Therefore, it IS accessible for other developers at this path:
node_modules/bower/bin/bower
A neater way to use a local install of bower is shown here.
Basically you need to use "npm run bower install" instead of "bower install" if you install bower through NPM locally and don't have it installed globally on your computer.