Laravel Forge deployment script fails with 'command not found' - laravel

Quick explanation: I have a staging and a production server, both with the same deployment script (the only difference is the repo branch the clone). The deployment script runs bower install which is globally installed on both servers.
To install it globally I changed npm config set prefix to /home/forge/.npm-packages and afterwards ran npm install -g bower (note sudo wasn't needed, that's the point of changing the prefix). Once again, this was done in both servers.
When I ssh into each server, and run bower -v, which bower it is clear the command DO exist, and it IS added to PATH env. It is the same output for both servers.
Manually running bower install on the project root works for both server.
The issue is the forge deployment script, which only fails on production (IKR? I don't know what was I expecting).
The actual output is:
/home/forge/.forge/provision-2394191.sh: line 8: bower: command not found
The interesting part is, in my attempt to debug, I manually ran provision-2394191.sh and it worked.
What is wrong with my production server?

Seems like adding the new /home/forge/.npm-packages to the $PATH using export was not enough. To solve this I had to manually add it to the /etc/environment file.

Related

Run script before installing packages with nodeLinker set to node-modules

I have to run a script (from my package.json file) before I run yarn install. The script sets up the configuration for a private package. In my .yarnrc.yml, I have nodeLinker: node-modules (and I want to keep it that way because I get other errors if I remove it).
The problem is that when I run yarn run myscript I have the following error:
Usage Error: Couldn't find the node_modules state file - running an install might help (findPackageLocation)
$ yarn run [--inspect] [--inspect-brk] [-T,--top-level] [-B,--binaries-only] <scriptName> ...
But I can't run install before the script since I have private packages that need the script before it gets installed.
I just switched from NPM to Yarn 3.2.0. With NPM, I was able to run the script before installing packages.

yarn berry run how to run installed packages

I see with yarn berry I get the plug'n'play feature instead of node_modules/
I couldn't find anything to suggest it supports running from installed packages.
For example with npm a workflow might be to run the installed version of webpack:
$ npm install --save-dev webpack
$ node node_modules/webpack/bin/webpack ...
A globally installed webpack might not be the same version. Worse yet, during Docker deployment, I get what's installed locally, the only node and npm are available globally. I thought I can do a preinstall script that does npm install -g yarn; yarn set version berry but then I'm not sure how to do webpack, jest, babel, etc, and the thought that I should have to install them all globally during the same preinstall hackaround seems like several steps backwards.
Is there some way to run from locally-installed packages that I'm missing?
I saw this possibly related question - Yarn Berry - Run a Node Script Directly
But the answer there seems a bit off the point - I'm not running any js, I'm trying to type in a package.json script, i.e. something that can run from the shell.
Why not just use yarn run <bin> (or simply yarn <bin>)? If you are in a repository set to use yarn berry, that will run any package bin file.
yarn node <file> will run any .js file with Plug n' Play set up. No need to install those dependencies globally, except for maybe yarn classic.
I was trying to do yarn some-bin and kept getting:
Couldn't find a script named "some-bin".
I eventually figured out it was because the package that provides some-bin is installed inside a workspace and not at the root of my project. So instead I had to run:
yarn workspace my-workspace some-bin
And that worked.

How can I run npm install as part of an Octopus Deploy?

After I've deployed my nodejs website, but before I update the IIS virtual directory, I need to execute npm install from the command line.
How can I do this with Octopus Deploy's scripts feature?
Either add a PreDeploy script with the command you want to run in your package or via the UI
I've marked Robert's answer as the correct one as the high-level approach is the one I needed. For the record here's the PowerShell script I used-
$installDirectory = $OctopusParameters['Octopus.Action.Package.CustomInstallationDirectory']
cd $installDirectory
npm install --silent

NPM Packages (with CLI) installed globally return command not found

I've had this happen twice to me before. The first time I assumed it was an error with NPM, so I uninstalled Node & NPM and didn't use the package that was giving me an error.
I did a fresh install & began working on another project. I'd installed the package (and the version of it with cli). The command line command worked during the terminal session during which i'd installed it both globally and in my project. However in other terminal tabs and in new terminal sessions the command returns command not found.
when I run npm root i receive:
/Users/MYUSERNAME/node_modules
and when I run npm root -g, i receive:
/Users/MYUSERNAME/.npm-global/lib/node_modules
For what it's worth the two packages I've tried this with are mjml (and mjml-cli) and gulp (and gulp-cli). I've uninstalled both and reinstalled again from my root directory using the -g flag and that doesn't seem to have changed anything.
I appear to have missed this somewhere in the googling I did before asking this question.
Apparently I had been accidentally installing global packages in my local folder (/Users/YOURUSERNAME/node_modules).
Running npm config set prefix /usr/local fixed the issue.

Can't build a Web Project in TeamCity

I am using TeamCity as my CI server(mac).I am trying to build a web project. When I use grunt serve or grunt buildproduction after changing directory to the cloned folder,it's working perfectly fine.But when I do this via TeamCity server it is giving an error You need to have Ruby and Compass installed and in your system PATH for this task to work and gets aborted due to warnings. Ruby and Compass is already installed in the server.Please help me on this.
rm -rf $(pwd)/node_modules/*
rm -rf $(pwd)/bower_components/*
npm cache clear
npm install
npm install bower
npm install grunt-ftp-push --save-dev
bower install
grunt buildproduction
This is the Command Line buildstep which I used in Teamcity..
I would say you probably use a different user or the shell environment is different (interactive vs non-interactive) when you run these commands manually and when it runs through TC it can't find those packages in the environment/PATH

Resources