Elasticbeanstalk npm: command not found - npm

My project was working since 2 years with no problem.
But this morning, It becomes to return error.
sudo: npm: command not found
Here's my .ebextensions file
I'm using Amazon Linux 2 with PHP.
option_settings:
- namespace: aws:elasticbeanstalk:application:environment
option_name: COMPOSER_HOME
value: /root
# Point the app root to the public/ folder.
- namespace: aws:elasticbeanstalk:container:php:phpini
option_name: document_root
value: /p
ublic
# Set here your php.ini `memory_limit` value.
- namespace: aws:elasticbeanstalk:container:php:phpini
option_name: memory_limit
value: 256M
container_commands:
00_copy_env_file:
command: "mv /tmp/.env /var/app/staging/.env"
01_install_composer_dependencies:
command: "sudo php /usr/bin/composer.phar install --no-dev --no-interaction --prefer-dist --optimize-autoloader"
cwd: "/var/app/staging"
02_install_node_dependencies:
command: "sudo npm install"
cwd: "/var/app/staging"
03_build_node_assets:
command: "npm run dev"
cwd: "/var/app/staging"
04_link_storage_folder:
command: "php artisan storage:link"
cwd: "/var/app/staging"
05_run_migrations:
command: "php artisan migrate --force"
cwd: "/var/app/staging"
leader_only: true
06_run_migrations:
command: "php artisan key:generate"
cwd: "/var/app/staging"
07_run_migrations:
command: "php artisan passport:install"
cwd: "/var/app/staging"
What's change on elasticbeanstalk on AWS. Whats wrong with my configuration?
All my websites are down at the same time, this morning.
edit:
.platform/hooks/prebuild/install_latest_node_js.sh file is below.
#!/bin/sh
# Install Latest Node
# Some Laravel apps need Node & NPM for the frontend assets.
# This script installs the latest Node 12.x alongside
# with the paired NPM release.
sudo yum remove -y nodejs npm
sudo rm -fr /var/cache/yum/*
sudo yum clean all
curl --silent --location https://rpm.nodesource.com/setup_12.x | sudo bash -
sudo yum install nodejs -y
# Uncomment this line and edit the Version of NPM
# you want to install instead of the default one.
# npm i -g npm#6.14.4

Try this command:
sudo apt-get install npm

Related

Run yarn from Dockerfile in ddev

This is a followup to How can I add and use nvm in a DDEV web container?
My dockerfile now looks like this:
ARG BASE_IMAGE
FROM $BASE_IMAGE
ENV NVM_DIR=/usr/local/nvm
ENV NODE_DEFAULT_VERSION=v8.16.1
RUN curl -sL https://raw.githubusercontent.com/nvm-sh/nvm/v0.34.0/install.sh -o install_nvm.sh
RUN mkdir -p $NVM_DIR && bash install_nvm.sh
RUN echo "source $NVM_DIR/nvm.sh" >>/etc/profile
RUN bash -ic "nvm install $NODE_DEFAULT_VERSION && nvm use $NODE_DEFAULT_VERSION"
RUN chmod -R ugo+w $NVM_DIR
RUN npm install -g foundation-cli
RUN npm install -g gulp-cli
RUN yarn --cwd foundation-src install
The last line returns an error: Service 'web' failed to build: The command '/bin/sh -c yarn --cwd foundation-src install' returned a non-zero code: 1'
When I ddev ssh and then run yarn --cwd foundation-src install it does the job (running yarn in the foundation-src folder).
I also tried RUN (cd foundation-src; yarn install;) but no luck either. I prefer the first command anyway. But what is going on? Why can I run stuff from inside the container but not from the dockerfile?
Your command is RUN yarn --cwd foundation-src install - it's assuming that there is a subdirectory "foundation-src" under the current directory.
But the Dockerfile is running long, long before your source is anywhere useful. The container has not been run yet, nothing is mounted. So you can't do things that require your source code to be present.
Since this command appears to require your source code to be present, I think you'll be better doing this as a post-start hook, perhaps
hooks:
post-start:
- exec: "yarn --cwd foundation-src install"
Since actions like yarn install happen irregularly, it's also easy to ddev exec yarn --cwd foundation-src install and also easy to create a custom command to do that when you need it.

How install and run vue js application on Centos 7

I want to install vuejs and run it on Centos 7, I want to run it inside a specific folder.
[updated]
It's a little bit different, but works fine to me on CentOS 7
(deprecated but working fine)
$ curl -sL https://rpm.nodesource.com/setup_10.x | sudo bash -
$ sudo yum install -y nodejs
$ node --version
$ npm --version
$ sudo npm install -g #vue/cli
$ vue create [projectname]
go to the folder of project name:
$ cd projectname
$ npm run serve
open your internet browser and type http://localhost:8080/
You need to install Node and NPM first. On CentOS 7 you can do this by running the following commands.
curl -sL https://rpm.nodesource.com/setup_10.x | sudo bash -
sudo yum install nodejs
After this, confirm that Node and NPM are installed by running node --version and npm --version.
Then you need to install vue-cli. This makes creating Vue applications very easy. Install it by running npm install -g #vue/cli. After that has installed, you can create new projects by running vue create <project-name>. Once you have created the project, you can run it locally using npm run serve.

Gitlab ci config for Cypress tests on Svelte SSR (Sapper)

New to Sapper, the SSR version of Svelte.
I try to get the tests from the basic template to run in Gitlab.
My test job in the .gitlab-ci.yml looks like this:
test-job:
stage: test
image: cypress/base:10
script:
- npm install --save-dev cypress
- npm i serve
- serve -s build -l 3000 & yarn wait-on http://localhost:3000
- $(npm bin)/cypress verify
- $(npm bin)/cypress run
When I tried - npm run cypress run after - npm install it could not find the server. Then i tried to install serve but I still get an error:
$ serve -s build -l 3000 & yarn wait-on http://localhost:3000
/bin/bash: line 96: serve: command not found
Thanks for any pointers.

Vagrant VirtualBox Local Dev Env, Ubuntu, Yarn, Vue CLI 3 - Issues

I am trying to setup a local development environment consisting of:
Ubuntu server vagrant box
My existing vuejs project created using Vue CLI 3 and passed to vagrant via synced_folder
Then run yarn run serve and access this on my host using port forwarding on the vagrant box.
Background:
I have developed a vue CLI 3 project on my Ubuntu 16.04 laptop which is working well, however, I want to move this inside of a vagrant box to keep my local machine tidy. I currently use yarn run serve which works well. I want to be able to run this command inside a new vagrant development environment.
Summary of Problems/Issues:
the vue command is not found after installing its dependencies
permission issues spat out by yarn when attempting to run yarn run serve inside vagrant box
there is an fsevents#1.2.4 message when yarn global add #vue/cli
Provisioning the local dev environment:
The Vagrantfile:
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure("2") do |config|
config.vm.define "webserver_dev" do |webserver_dev|
webserver_dev.vm.box = "ubuntu/xenial64"
webserver_dev.vm.network "private_network", ip: "192.168.33.10"
webserver_dev.vm.network "forwarded_port", guest: 80, host: 8888
webserver_dev.vm.network "forwarded_port", guest: 8080, host: 8080
webserver_dev.vm.hostname = "develop.dev"
webserver_dev.vm.synced_folder ".", "/var/www", :mount_options => ["dmode=777", "fmode=666"]
webserver_dev.ssh.forward_agent = true
webserver_dev.vm.provider "virtualbox" do |vb|
vb.memory = "1824"
vb.cpus = "2"
end
end
end
Provisioning of the vagrant box: ubuntu/xenial64 (virtualbox, 20180802.0.0):
sudo apt update && sudo apt upgrade
sudo apt install build-essential libssl-dev -y
# install node and npm:
cd ~
curl -sL https://deb.nodesource.com/setup_10.x -o nodesource_setup.sh
sudo bash nodesource_setup.sh
# install yarn
curl -sL https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
sudo apt-get update && sudo apt-get install yarn
# Show installed versions
yarn -v (outputs 1.9.4)
node -v (outputs v10.9.0)
npm -v (outputs 6.2.0)
Problems/Issues Output:
When I navigate to my existing vue project folder and run yarn run serve inside vagrant ssh I get the following error:
yarn run v1.9.4
$ vue-cli-service serve
/bin/sh: 1: vue-cli-service: Permission denied
error Command failed with exit code 126.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
When I run sudo yarn run serve
(I shouldn't have to run this as root anyway but:)
yarn run v1.9.4
$ vue-cli-service serve
/bin/sh: 1: vue-cli-service: Permission denied
error Command failed with exit code 126.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
Running vue --version
vagrant#cc:~$ vue --version
No command 'vue' found, did you mean:
Command 'vpe' from package 'texlive-latex-extra' (universe)
vue: command not found
Output from running yarn global add #vue/cli
As shown in the official vue-cli installation documentation
NOTE: The fsevents#1.2.4 message I get. Could this what is causing the problems?
vagrant#cu:~$ yarn global add #vue/cli
yarn global v1.9.4
[1/4] Resolving packages...
[2/4] Fetching packages...
[----------------------------------------------------------------------------------------------------------------------------------------] 0/617(node:7694) [DEP0005] DeprecationWarning: Buffer() is deprecated due to security and usability issues. Please use the Buffer.alloc(), Buffer.allocUnsafe(), or Buffer.from() methods instead.
info fsevents#1.2.4: The platform "linux" is incompatible with this module.
info "fsevents#1.2.4" is an optional dependency and failed compatibility check. Excluding it from installation.
[3/4] Linking dependencies...
[4/4] Building fresh packages...
success Installed "#vue/cli#3.0.1" with binaries:
- vue
Done in 58.25s.
Summary:
Has anyone out there achieved a local development environment where they are successfully able to run yarn run serve inside it and access the result on their host machine?
I would be very interested to see how other developers approach their local development for vue js projects which also have other services requiring reverse proxys (eg node js app running on a different port).
I have spent an awful lot of time trying to set this up to no avail. Maybe these tools just don't play well together. If you think you could help I would be very grateful. Thanks
Temporary Workaround: - inspired by this post
After further troubleshooting I found the problem is certainly a permissions related issue (not related to vue-cli).
I think that as my vagrant is using virtualbox, there is a virtualbox issue with symbolic links from the synced folder from my host, which may change permissions and stops chmod command from having any effect on files. In my case the execute flag from node_modules/.bin directory was not-executable.
For anyone with similar issues here is my current workaround to this issue (Do yourself a favour and read https://github.com/hashicorp/vagrant/issues/713 I wish I'd found it earlier!):
1) copy the projects package.json to: the yarn global directory: /home/vagrant/.config/yarn/global/
cp /var/www/project/package.json /home/vagrant/.config/yarn/global/
2) Install the projects dependencies globally in the yarn users directory:
cd /home/vagrant/.config/yarn/global
yarn install
3) Now returning to the project and running yarn run serve works as it uses the node_modules from /home/vagrant/.config/yarn/global/node_modules/.bin/ which has the correct executable permissions.
cd /var/www/project/package.json
yarn run serve
Example of cause of the issue:
1) Change directory to your project and ls -l to see permissions:
cd /var/www/project/node_modules/.bin
ls -la
Outputs:
lrw-rw-rw- 1 vagrant vagrant 18 Aug 29 00:21 which -> ../which/bin/which
2) Attempt to make file executable:
chmod 777 ./which (adding sudo doesn't make this work either)
Outputs:
lrw-rw-rw- 1 vagrant vagrant 18 Aug 29 00:21 which -> ../which/bin/which
OLD ANSWER - DIDN'T WORK: The solution I am now using is taken from here: Source
Adding this to the Vagrantfile enables symbolic links to work properly.
I am using ubuntu on my host and guest machines so can't be sure this will work for Mac and Windows.
config.vm.provider "virtualbox" do |v|
v.customize ["setextradata", :id, "VBoxInternal2/SharedFoldersEnableSymlinksCreate/vagrant", "1"]
end
Further Reading:
https://github.com/hashicorp/vagrant/issues/713
You need to use sudo when installing vue-cli.
The vue-cli documentation at https://cli.vuejs.org/guide/installation.html states that:
To install the new package, use one of the following commands. You
need administrator privileges to execute these unless npm was
installed on your system through a Node.js version manager (e.g. n or
nvm).
npm install -g #vue/cli
# OR
yarn global add #vue/cli

How do I use FPM to generate a Global NPM module as an rpm?

I want to install a node module that I have downloaded like pm2and package it as a rpm. When I run the rpm command I want the package installed globally:
example npm install -g pm2
Do I create a the rpm from fpm like this?
fpm -s npm -t rpm pm2.zip
fpm will automatically download it from the npm registry. So the following command is enough.
fpm -s npm -t rpm pm2
Created package {:path=>"node-pm2-2.7.1-1.x86_64.rpm"}