I set NODE_ENV to production and tried to install dependencies using a Capfile which contains this:
run "cd #{latest_release} && npm config set production=true && npm install --production"
or this:
run "cd #{latest_release} && npm install --production"
but I always get also the dev dependencies, which is annoying because after a few releases all the inodes are taken and I cannot create any other files on the deploy machine.
I set the environment variable like this in the Capfile:
set :default_environment, {
'NODE_ENV' => 'production'
}
run "echo $NODE_ENV"
and it echoes the correct value.
If I execute
npm install --production
from within a shell, it works correctly. The user that makes the capistrano deploy and this shell user are the same, so I'm quite lost. Any hints?
The problem was:
sudo npm link
which I ran after the install command and which installs all dependencies. The fix is:
sudo npm link --production
Related
After running npm install --global yarn, I get an output that says:
> yarn#1.22.18 preinstall C:\Users\(me)\AppData\Roaming\npm\node_modules\yarn
> :; (node ./preinstall.js > /dev/null 2>&1 || true)
C:\Users\(me)\AppData\Roaming\npm\yarn -> C:\Users\(me)\AppData\Roaming\npm\node_modules\yarn\bin\yarn.js
C:\Users\(me)\AppData\Roaming\npm\yarnpkg -> C:\Users\(me)\AppData\Roaming\npm\node_modules\yarn\bin\yarn.js
+ yarn#1.22.18
updated 1 package in 0.389s
When I run "yarn serve" it tells me that 'yarn' is not recognized as a command. I've tried this in powershell and CMD and neither works.
It ended up being a path issue. I used npm list -g to reveal where yarn was installed. Then I searched for "Edit the environment variables" in Windows and added the containing folder to the PATH.
I also updated my node and npm to the latest versions before doing these steps.
Just put --> npm install -g yarn
The problem is that you're installing nvm as root, and when npm runs the lifecycle scripts it downgrades the permissions, making it impossible to even run Node scripts, since the node binary can only be accessed by root.
I have installed serve with npm as "npm install serve -g" and also with yarn "yarn global add serve", but when I try to run "serve -s build" it says that "Command 'serve' not found.
You should not install the packages globally.Try to do the following-
npm uninstall -g serve
npm i -S serve
Let me know if this works.
I had same problem too and this helped me to fix it so try this after installing serve;
npx serve -s build
or
npx serve -s build -p 8000
(8000 = it depends by your choice)
I don't know why but this worked for me
None of these above answers worked for me, so this is what works for me :
sudo su
npm install -g serve
Installing as root helps globally installing serve
Make sure to have this in your .bashrc or .zshrc
if you're using Yarn:
export PATH="$PATH:$(yarn global bin)"
if you're using NPM:
export PATH="$(npm bin -g):$PATH"
So that the shell would know where to look for executables such as serve, npx, live-server etc that are installed globally.
Make sure to reload your shell config:
source ~/.bashrc // or ~/.zshrc
If anyone still gets the problem, try this:
npm uninstall -g serve
npm i -S serve
yarn global add serve
I faced the same problem, what I did was run the command yarn serve -s build
If you got it installed with npm then you can just add npm before the suggested command
I have a npm package (npm v 5.5.1 and node version is 9.2.0). If i run npm install on local machine then the postinstall defined in package.json is executed but if I run the same command RUN npm install in a Docker file i.e. when the command is run inside the container then the postinstall step is not executed. Any inputs what could be the issue here ?
Try running install with --unsafe-perm option. When running as root, npm won't run any scripts.
Alternatively, create a user in the Dockerfile and switch to that user:
FROM ...
RUN groupadd -r app && useradd -r -g app app
USER app
Another option to the selected answer (#yamenk's):
You could add this line to your dockerfile to configure your npm config inside the container (thus, allowing the execution of the postinstall script with the necessary permissions):
FROM ...
RUN npm config set unsafe-perm true
I wanted to know how to use nodemon, and push it to a git repo, and have other developers on the project be able to use nodemon without having to run the command npm install -g nodemon. Ideally, I would like all developers on the project to be able to just run npm start and nodemon is called whether or not it's installed globally. I've already run npm install --save-dev nodemon, and I'm mostly curious if there is a way to get nodemon to be run from within node_modules, in my start command in the scripts section of the package.json file.
If you install it locally, i.e. without the -g flag, it's available in ./node_modules/.bin/nodemon. So just configure that path in your npm start script.
For example:
"start" : "./node_modules/.bin/nodemon app.js"
I'm running a nodejs application's build on jenkins. I run node as shell script step, because I have some limitations in terms of the plugins I can install in this jenkins instance.
This is what the npm install step looks like:
#!/bin/bash +x
source ~/.bashrc
cd $WORKSPACE/ && \
nvm use 7.8.0 && node --version && npm install
The problem I have is, when npm install finishes, it doesn't install everything. If I ssh into the box where jenkins is installed and run npm install inside that project's workspace, with the same user jenkins uses, it works ok. Any ideas?
EDIT
I just realized the dependencies that it's not installing are devDependencies
The problem was I had the node env set to production, and of course, it wouldn't get the devDependencies...