2

I would like to have an OS which support nodejs. In my yocto project at layer.conf file I add IMAGE_INSTALL_append = " nodejs" IMAGE_INSTALL_append = " nodejs-npm" which result in to have an OS with nodejs support afer bake. Now I want to add some NPM packages also like basic-auth etc. would you please help me. kind regards.

sam
  • 1,363
  • 1
  • 20
  • 32

2 Answers2

4

In order to add an npm package into your image, you need to create a recipe for it.

Yocto has an npm source scheme handler, and you can use registry.npmjs.org to create a recipe fetching your wanted package.

Create a recipe with devtool:

devtool add "npm://registry.npmjs.org;name=basic-auth;version=latest"

You can set a specific version as well.

The recipe would be the following:

  • basic-auth_2.0.1.bb :
# Recipe created by recipetool
# This is the basis of a recipe and may need further editing in order to be fully functional.
# (Feel free to remove these comments when editing.)

SUMMARY = "node.js basic auth parser"
# WARNING: the following LICENSE and LIC_FILES_CHKSUM values are best guesses - it is
# your responsibility to verify that the values are complete and correct.
LICENSE = "MIT"
LIC_FILES_CHKSUM = "file://LICENSE;md5=42fffe6fe0b70501d52150ebb52113df \
                    file://node_modules/safe-buffer/LICENSE;md5=badd5e91c737e7ffdf10b40c1f907761"

SRC_URI = "npm://registry.npmjs.org/;name=basic-auth;version=latest"

NPM_SHRINKWRAP := "${THISDIR}/${PN}/npm-shrinkwrap.json"

inherit npm

# Must be set after inherit npm since that itself sets S
S = "${WORKDIR}/npmpkg"
LICENSE_${PN}-safe-buffer = "MIT"
LICENSE_${PN} = "MIT"

It compiles correctly.

You can move it to your custom layer after testing it with devtool:

devtool finish basic-auth <path/to/meta-custom> or
devtool finish basic-auth <layer/in/bblayers.conf>

For more information about npm handling check this link

I encourage you to read more about Yocto NPM handling in their official documentation in this link

EDIT:

If you encounter the error:

is missing the required parameter 'Parameter 'package' required'

just change name to package :

devtool add "npm://registry.npmjs.org;package=basic-auth;version=latest"
Talel BELHADJSALEM
  • 3,199
  • 1
  • 10
  • 30
  • Many Many Thanks. With devtool I get this error "ERROR: URL: 'npm://registry.npmjs.org/;name=basic-auth;version=latest' is missing the required parameter 'Parameter 'package' required'". Any Idea about this error? – sam Mar 04 '22 at 08:59
  • Check my EDIT. Just replace `name` to `package` – Talel BELHADJSALEM Mar 04 '22 at 10:16
  • You are right. I managed it like : devtool add "npm://registry.npmjs.org;name=basic-auth;version=2.0.1;package=basic-auth" – sam Mar 04 '22 at 13:26
  • If my answer fixed your issue, it would be so helpful if you accept it as "Correct Answer" – Talel BELHADJSALEM Mar 04 '22 at 13:56
  • still working on it, when I finished, sure. Many thanks up to now. – sam Mar 04 '22 at 16:37
  • When I try to bake I face with this error : "ERROR: Failure expanding variable TUNE_FEATURES_tune-armv7at-neon, expression was ${TUNE_FEATURES_tune-armv7at} neon which triggered exception RecursionError: maximum recursion depth exceeded while calling a Python object " any Idea ? – sam Mar 10 '22 at 11:08
0

You can add any package which is available by Openembedded Layer in your Yocto release. Please look to Openembedded Layer to find the package you want. After that, you can add any package via your local.conf file.

Here is a third party library

If you don't find the package on the page, you need to compile it on your own using a compiler for your platform and add it manually by recipe.

kluszon
  • 375
  • 5
  • 19