【问题标题】:How to Add Nodejs Packages to Yocto?如何将 Nodejs 包添加到 Yocto?
【发布时间】:2022-03-04 18:16:26
【问题描述】:

我想要一个支持 nodejs 的操作系统。在我的 layer.conf 文件中的 yocto 项目中,我添加了 IMAGE_INSTALL_append = "nodejs" IMAGE_INSTALL_append = "nodejs-npm" 这导致有一个带有nodejs的操作系统支持afer bake。现在我想添加一些 NPM 包,比如 basic-auth 等。 你能帮帮我吗? 亲切的问候。

【问题讨论】:

    标签: node.js npm yocto yocto-recipe


    【解决方案1】:

    要将npm 包添加到您的图像中,您需要为其创建一个配方。

    Yocto 有一个 npm 源方案处理程序,您可以使用 registry.npmjs.org 创建一个配方来获取您想要的包。

    使用 devtool 创建配方:

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

    您也可以设置特定版本。

    配方如下:

    • 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"
    

    它编译正确。

    您可以在使用devtool 对其进行测试后将其移至您的自定义层:

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

    有关npm处理的更多信息,请查看link

    我鼓励您阅读更多关于 Yocto NPM 处理在其官方文档中的link

    编辑

    如果遇到错误:

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

    只需将 name 更改为 package

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

    【讨论】:

    • 非常感谢。使用 devtool 我收到此错误“错误:URL:'npm://registry.npmjs.org/;name=basic-auth;version=latest' is missing the required parameter 'Parameter 'package' required'”。关于这个错误的任何想法?
    • 检查我的编辑。只需将name 替换为package
    • 你是对的。我像这样管理它:devtool add "npm://registry.npmjs.org;name=basic-auth;version=2.0.1;package=basic-auth"
    • 如果我的回答解决了您的问题,如果您接受它作为“正确答案”将会非常有帮助
    • 我还在努力,当我完成时,当然。到目前为止,非常感谢。
    【解决方案2】:

    您可以在 Yocto 版本中添加 Openembedded Layer 可用的任何数据包。请查看Openembedded Layer 以找到您想要的数据包。之后,您可以通过 local.conf 文件添加任何数据包。

    Here is a third party library

    如果您在页面上没有找到该数据包,则需要使用适合您平台的编译器自行编译并通过配方手动添加。

    【讨论】:

      猜你喜欢
      • 2018-07-24
      • 1970-01-01
      • 2021-10-19
      • 1970-01-01
      • 2021-09-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多