Problem with installing and running aws-amplify cli and global npm packages in general - npm

I'm trying to install the aws amplify cli on my Mac. It seems to install ok, but when i run it afterwards is responds with
bash: amplify: command not found
I was thinking that it probably had something to do with the directory of the global npm packages, so i ran
$ npm -g root
Which returned:
/usr/local/lib/node_modules/node/lib/node_modules
It seems very odd that my node_modules are placed inside another node modules folder.
When i run:
$ which npm
it returns:
/usr/local/bin/npm
I also tried listing my global packages with the command
$ npm list -g --depth=0
Which returned:
/usr/local/lib/node_modules/node/lib
├── #angular/cli#7.3.1
├── #aws-amplify/cli#1.5.1
├── ng#0.0.0
├── npm#6.9.0
├── npm-check#5.9.0
├── tsc#1.20150623.0
├── typeorm#0.2.16
└── typescript#3.2.2
Can somebody please help me sort this mess out?

I ran into the same issue following the AWS Tutorial for deploying a React App: https://aws.amazon.com/getting-started/hands-on/build-react-app-amplify-graphql/module-two/
I used the command below as stated in the tutorial to install the Amplify CLI:
npm install -g #aws-amplify/cli
The packages installed successfully but after moving to the next step of the tutorial I got the same error:
amplify: command not found
The issue was the package was being installed outside my path and could not be found. However running the curl command below added the necessary line to my zshrc file and configured my $Path correctly.
curl -sL https://aws-amplify.github.io/amplify-cli/install | bash && $SHELL
(https://docs.amplify.aws/cli/start/install)
This is the result of running the curl command above
The line below was automatically added to my .zshrc file:
# Added by Amplify CLI binary installer
export PATH="$HOME/.amplify/bin:$PATH"

In case if someone is installing amplify using curl on Mac, then you need to edit your .zprofile (if you are using zsh terminal) or .bash_profile.
Open your terminal
1. cd
2. vim .zprofile
3. Press i, then paste this line
export PATH="$HOME/.amplify/bin:$PATH"
4. Press Esc and :wq to save this file
5. Restart your terminal

Related

Where can I find a list of all npm flags / tags / options?

I am looking for the meaning of the flag --u as in "npm run test --u" but I don't know where all the flags are documented.
Here are the bottom are some shorthands, but besides "gangster" and other cool ones, I couldn't find --u
https://github.com/npm/npmconf/blob/master/config-defs.js#L405
"npm run test --u" ("--u") belongs to jest flag --updateSnapshot. If you run npm run test help or npm test help you will get all the flags of jest.
Inorder to get npm flags list or npm commands you can run this command npm -l
Here are the list of other npm flags that you might need:
-u or --update: Updates the packages installed in you current working directory
-g or --global: Installs the package globally rather than in your local working directory.
-v or --version: Displays the version of npm.
-h or --help: Displays help information for the npm command.
-l or --long: Shows extended information for the installed packages.
-j or --json: Outputs the npm registry data in json format.
-S or --save: Saves the package as a dependency in your package.json file. As of npm version 5, you might not need this anymore as packages will be saved by default into the package.json file
-D or --save-dev: Saves the package as a dev-dependency in the package.json file.
-O or --save-optional: Saves the package as an optional dependency in the package.json file.
-E or --save-exact: Saves the package at the exact version specified in the package.json file.
-P or --save-prod: Saves the package as a production dependency in the package.json file.
-B or --save-bundle: Saves the package as a bundled dependency in the package.json file.

Yocto recipe fails to install npm package

I have a recipe that installed some NPM packages that worked on an older version of Yocto.
After upgrading to sumo, the recipe fails with the following error:
installnpmpackages/0.0.1-r0/temp/run.do_compile.7272: npm: not found
| WARNING: exit code 127 from a shell command.
I tried using the developer shell and NPM does work in that case.
The do_compile from the recipe:
do_compile() {
# Create a working directory
mkdir -p ${WORKDIR}/scratch
# changing the home directory to the working directory, the .npmrc will be created in this directory
export HOME=${WORKDIR}/scratch
# configure cache to be in working directory
npm set cache ${WORKDIR}/scratch/npm_cache
# clear local cache prior to each compile
npm cache clear
# compile and install node modules in source directory
cd ${WORKDIR}/scratch
npm --arch=${TARGET_ARCH} --verbose install node-gyp
npm --arch=${TARGET_ARCH} --verbose install connect
npm --arch=${TARGET_ARCH} --verbose install socket.io
#npm --arch=${TARGET_ARCH} --verbose install sqlite3
#npm --arch=${TARGET_ARCH} --verbose install serialport
npm --arch=${TARGET_ARCH} --verbose install express
npm --arch=${TARGET_ARCH} --verbose install csv
npm --arch=${TARGET_ARCH} --verbose install md5
# clear local cache before we package. No need to copy over all this cache stuff; just need the modules.
npm cache clear
}
Note sqlite3 and serialport are commented out as they did not work on the previous version.
What needs to be changed with sumo (vs morty) for NPM to function in a recipe?
Thank you in advance!
I found a simple solution.
I created individual recipes using devtool add.
Here is the command used to create a recipe for the serialport npm module:
devtool add "npm://registry.npmjs.org;name=serialport;version=7.1.4"
I'm answering to #Hsn comment as my account is new and I don't have 50 reputation.
If you are able to add a recipe with devtool and it worked, you can use devtool as well to finish working on the recipe and tell devtool in which meta you want to put the recipe like :
devtool finish recipe_name meta-destination
And in order to put it into your final OS rootfs, you need to add it to your image bb file, for example : image-dev.bb :
IMAGE_INSTALL_append += "recipe_name"
Make sure also that the meta which holds your recipe is present in your bblayers.conf.

How to run the official vue.js examples?

I git cloned vue, cd'ed into one of the examples folder and ran npm install. Everything went fine, then I ran npm run dev and it gets stuck at this stage. Is there anything else I should do to run this locally?
npm run dev
> vue#2.4.2 dev /vue
> rollup -w -c build/config.js --environment TARGET:web-full-dev
bundling...
bundled in 2456ms. Watching for changes...
You need to run a local web server.
Try this:
Install http-server package with npm:
$ sudo npm install -g http-server
Run it in the root of the vue cloned folder:
$ git clone git#github.com:vuejs/vue.git
$ cd vue
$ http-server -o -c .
In yout browser, navigate to the examples folder, for instance:
http://127.0.0.1:8081/examples/select2/
They are the same from here:
https://v2.vuejs.org/v2/examples/

Babel Errors in Cloud 9 IDE

Getting a bunch of babel errors when running npm run dev with the Vue cli.
This only happens in Cloud9.
Any thoughts on what could be the issue or how to disable errors like this before running npm run dev?
All babel related it looks like.
I couldn't re-create the babel error messages but it's possible that it could be caused if npm/node is not up-to-date. (Vue-cli wasn't starting dev server before the installation below)
Is your repository public where you're getting the error messages? Then I could have a look at the errors.
If removing node_modules folder is not helping,
here is how you can create a new IDE workspace for vue.js ($ for commands in bash terminal):
Create a blank Ubuntu workspace
Check that nvm is installed & up-to-date with (check version of install script here):
$ curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.32.1/install.sh | bash
$ nvm install node 6
$ npm i vue-cli -g
$ vue init webpack yourAppName
$ cd yourAppName
$ npm install
$ npm run dev
Click preview to test that Vue server is running as expected
Here is a link to a HelloWorld Vue app in cloud9 ide.
If you have an existing app you can also use git to clone it into your new workspace instead of creating a new app.

How to change npm path

All my npm packages work, but my npm package list shows empty. I am sure this is issue with a path but not sure how to fix it.
Which gulp gives me >
[~] ruby-2.2.3 $ which gulp
/usr/local/bin/gulp
Which npm gives me >
[~] ruby-2.2.3 $ which npm
/usr/local/bin/npm
npm list gives me >
[~] ruby-2.2.3 $ npm list
/Users/kimmo
└── (empty)
It looks like you are confusing packages that are installed globally with those locally. The paths for gulp and npm look like the global install locations. Packages you install locally will be found under a node_modules folder in the root of your project.
You can confirm this by comparing the results from:
npm ls -g --depth=0
npm ls --depth=0
The first command will show the globally installed packages. The second will show the local packages.
At the top of the resulting output, each shows the directory where the global or local install is located.
Finally, the --depth=0 flag only shows the packages that were required and not the dependencies of those packages (and those packages, etc). I find that most of the time, that's all I care about. If you agree, you can easily make this a default with npm config set depth 0 or by editing your .npmrc file in your home directory.
So! My guess is that you installed gulp with the -g flag but you haven't installed anything locally (with no flag, so to speak). That's why there's a difference between what which is showing and npm ls is showing.