Yocto recipe fails to install npm package - npm

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.

Related

How can I set the npm version in gitlab CI?

I have a gitlab pipeline for an Angular project with the image in .gitlab-ci.yml
image: node:16
build:
stage: build
script:
- npm ci
- nodejs -v
- npm -v
- npm run build:prod
- npm doctor
When the pipeline reaches the npm doctor it fails with the following error on npm version:
$ npm doctor
Check Value Recommendation/Notes
npm ping ok
npm -v not ok Use npm v7.24.0
node -v ok current: v16.9.1, recommended: v16.9.1
npm config get registry ok using default registry (https://registry.npmjs.org/)
which git ok /usr/bin/git
Perms check on cached files ok
Perms check on local node_modules ok
Perms check on global node_modules ok
Perms check on local bin folder ok
Perms check on global bin folder ok
Verify cache contents ok verified 1361 tarballs
How can I solve this?
In my machine I have the npm version v7.24.0 and the command succeeds.
Install npm before you do anything else, specifying a version, i.e. npm install npm#version -g.
For completeness, if you can't update the global npm, you can do so locally, by replacing npm with npx npm#latest or npx npm#7.24.0. npx will install npm if it needs to, locally, and then run the local installation.
Lastly you can install locally with npm install npm#latest and then run it with $(npm bin)/npm, but this is what npx is for.
Note that I don't understand why you're running npm doctor after a build. Presumably if you care about npm thining it's set up properly you should run it before the build, so the pipeline fails early.
P.S. I stupidly read 'github' as 'gitlab'. If you were using github I would recommend using
setup-node if only for dependency caching, which can seriously speed up pipelines. I don't know if gitlab does anything similar.

Cypress cannot run because this binary file does not have executable permissions

I was trying to create a new project in cypress and I got the following strange error message.
Steps:
npm init -y
npm install cypress --save-dev
I then did npx open cypress and I got the following message from my console
How do I fix this?
Cypress cannot run because this binary file does not have executable permissions here:
/Users/myName/Library/Caches/Cypress/7.5.0/Cypress.app/Contents/MacOS/Cypress
Reasons this may happen:
- node was installed as 'root' or with 'sudo'
- the cypress npm package as 'root' or with 'sudo'
Please check that you have the appropriate user permissions.
You can also try clearing the cache with 'cypress cache clear' and reinstalling.
----------
Platform: darwin (20.5.0)
Cypress Version: 7.5.0
You can do two things:
Run the command npm cypress cache clear and then again install cypress npm install cypress --save-dev and check.
Or, install npm globally without sudo using the command npm install -g. Then create a new folder and then run npm init, npm install cypress --save-dev and npx cypress open.
Do navigate to the cache directory by doing
cd /Users/myName/Library/Caches/
Here you have to delete Cypress directory completely by running the command
rm -rf Cypress
Now head over to your project directory and run the command
npx install cypress
Cypress will be installed in your system again. Next time you won't get any errors.
So, I had a chat with the dev team at Cypress and got the following answer. After reading the logs I had a feeling this might be the root cause. So please check you have the most up to date version of Node.js

install packages globally in google cloud platform

I'm trying to install some npm packages globally in google cloud platform each time the shell started.
I added these commands in $HOME/.customize_environment file.
#!/bin/sh
date -u
npm i -g #angular/cli
then, I open the file /var/log/customize_environment to see the log output from $HOME/.customize_environment
I found it executed and the date is displayed (the first line)
but npm couldn't installed with this error npm command not found
npm commands are available after the cloud shell starts, so I guess the file $HOME/.customize_environment is executed before installing node.
I tried to use the full path: /usr/local/nvm/versions/node/v12.14.1/bin/npm i -g #angular/cli, but I got this error
/usr/bin/env: ‘node’: No such file or directory
is there a way to automatically install npm packages globally?
The path env var isn't set or active. Use the full path of NPM location like that
/usr/local/nvm/versions/node/v12.14.1/bin/npm i -g #angular/cli
Be careful. if Cloud Shell update the version of NPM the path will change.
You can also try to add your NPM (without full path) command at the end of the ~/.bashrc file.

npm install runs correctly, but cannot run topojson

If I do:
npm init
npm install --save topojson
I end up with a package.json file and node_modules directory, all looking correct. But if I then do:
topojson
I see:
-bash: topojson: command not found
Why?
The answer to this issue turned out not to be related to npm - npm install topojson no longer installs a command-line tool called topojson. Confusingly, it used to, but the package has changed.
try this step
install globally using -g
1. install nodejs http://nodejs.org/
2. install npm https://npmjs.org/doc/README.html
3. run npm install -g topojson in your command prompt
4. use the command prompt to cd to the geojson file
5. run topojson -o myNewTopojsonFile.json myOldGeojsonFile.json

access npm modules locally in case npm server is down

I am looking to store npm modules in a cache/locally in case the npm server is down and I cannot access the modules.
I hear npm-cache or npm-offline work well, but I'm not sure if they actually solve the problem I face - which is accessing an npm module locally.
Any recommendations?
Install offline-npm with
sudo npm install -g offline-npm
offline-npm will run a local http server with the content of your cache. Launch the server with:
offline-npm -n -d
You can then install packages from your cache with:
npm --registry http://localhost:4873 install <packagename>
To inspect the content of your cache run:
npm cache ls
You can also add a package to your cache without installing it with:
npm cache add <package>
For more information, read the official documentation of offline-npm.