简体   繁体   English

在 rules_nodejs bazel 中运行 yarn_install (或 npm_install )后如何访问 node_modules 文件夹?

[英]How to access node_modules folder after running yarn_install (or npm_install ) in rules_nodejs bazel?

I'm relatively new to Bazel but this has taken longer than I felt it should.我对 Bazel 比较陌生,但这花费的时间比我想象的要长。 I am doing yarn_install in my workspace, and I am just trying to reference the installed node_modules so that I can put them in my new docker container.我正在我的工作区中执行yarn_install ,我只是想引用已安装的node_modules ,以便我可以将它们放入我的新 docker 容器中。

Workspace工作区

yarn_install(
    name = "npm",
    package_json = "//:package.json",
    yarn_lock = "//:yarn.lock",
)

BUILD.bazel构建.bazel

load("@io_bazel_rules_docker//nodejs:image.bzl", "nodejs_image")

nodejs_image(
    name = "webapi_image",
    # gets all the files in my directory
    data = glob(
        [
            "**/*",
        ],
        # references the node modules, but doesn't work :(
    ) + ["@npm//node_modules"],
    entry_point = "//:app.js",
)

I've been able to get specific packages (ie @npm//express ) but if I try to access node_modules then I just get我已经能够获得特定的包(即@npm//express )但是如果我尝试访问 node_modules 那么我就会得到

no such package '@npm//node_modules': Package is considered deleted due to --deleted_packages and referenced by '//:webapi_image'

I'm not sure I totally understand why I can access individual packages (ie @npm//express ) but not node_modules (ie @npm//node_modules ).我不确定我是否完全理解为什么我可以访问单个包(即@npm//express )但不能访问 node_modules(即@npm//node_modules )。

but after bumping around, I found if I just use the structure @npm//:node_modules , then it works finally.但是经过一番摸索,我发现如果我只使用结构@npm//:node_modules ,那么它终于可以工作了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM