如何在 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?

我对 Bazel 比较陌生,但这花费的时间比我想象的要长。我正在我的工作区中做 yarn_install,我只是想引用已安装的 node_modules,以便我可以将它们放入我的新 docker 容器中。

工作区

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

BUILD.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",
)

我已经能够获得特定的包(即 @npm//express),但如果我尝试访问 node_modules,那么我只会得到

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

我不确定我是否完全理解为什么我可以访问单个包(即 @npm//express)但不能访问 node_modules(即 @npm//node_modules)。

不过折腾了一番,发现直接用结构体@npm//:node_modules,总算可以了。