Kent Shikama
Kent Shikama

Reputation: 4060

How to change shell of npm install

I'm trying to npm install a package in Ubuntu 16.04. I get the following error message:

npm install 

...

> [email protected] bower-install /home/kent/Documents/padlock
> pushd app && bower install && popd app

sh: 1: pushd: not found

My Research

According to /bin/sh: pushd: not found, my problem is clearly that npm install is trying to execute pushd with sh not bash.

However, my default shell is already bash

$ env | grep SHELL
SHELL=/bin/bash
$ echo $SHELL
/bin/bash
$ echo $0
bash

and I'm not sure what I need to change. I've also tried adding SHELL=/bin/bash before I execute pushd app but I have had no luck with that either.

Upvotes: 4

Views: 2993

Answers (2)

Robo
Robo

Reputation: 1032

npm-scripts run using sh

Scripts are run by passing the line as a script argument to sh

https://docs.npmjs.com/misc/scripts#exiting

If you want to use bash for your scripts make the script

bash -c 'pushd app && bower install && popd'

Update: As of November 2017 you can now set script-shell in .npmrc to use a custom shell

Upvotes: 5

MarkHu
MarkHu

Reputation: 1859

I was able to work around a similar situation by creating this file in my project directory:

$ cat .npmrc

script-shell=/bin/bash

FWIW, the issue I stumbled upon was relying on bash-specific "curly-brace expansion" commands in the postinstall section of the package.json file for the offending module. That malformed command works in MacOS, but not Linux.

Upvotes: 3

Related Questions