错误加载包'':每个.bzl文件都必须有一个对应的包,但'@npm//:install_bazel_dependencies.bzl'没有

Posted

技术标签:

【中文标题】错误加载包\'\':每个.bzl文件都必须有一个对应的包,但\'@npm//:install_bazel_dependencies.bzl\'没有【英文标题】:error loading package '': Every .bzl file must have a corresponding package, but '@npm//:install_bazel_dependencies.bzl' does not have one错误加载包'':每个.bzl文件都必须有一个对应的包,但'@npm//:install_bazel_dependencies.bzl'没有 【发布时间】:2020-06-21 01:59:07 【问题描述】:

我正在将 Bazel 集成到 Angular 应用程序中。但是在运行 ibazel run //src:devserver 时,我得到了这些错误:

iBazel [8:08AM]: Error getting Bazel info exit status 2
iBazel [8:08AM]: Querying for files to watch...
Loading: 0 packages loaded
ERROR: error loading package '': Every .bzl file must have a corresponding package, but '@npm//:install_bazel_dependencies.bzl' does not have one. Please create a BUILD file in the same or any parent directory. Note that this BUILD file does not need to do anything except exist.
Loading: 0 packages loaded
Loading: 0 packages loaded
iBazel [8:08AM]: Bazel query failed: exit status 7
Loading: 0 packages loaded
ERROR: error loading package '': Every .bzl file must have a corresponding package, but '@npm//:install_bazel_dependencies.bzl' does not have one. Please create a BUILD file in the same or any parent directory. Note that this BUILD file does not need to do anything except exist.
Loading: 0 packages loaded
Loading: 0 packages loaded
iBazel [8:08AM]: Bazel query failed: exit status 7
iBazel [8:08AM]: Running //src:devserver
Loading: 0 packages loaded
ERROR: error loading package '': Every .bzl file must have a corresponding package, but '@npm//:install_bazel_dependencies.bzl' does not have one. Please create a BUILD file in the same or any parent directory. Note that this BUILD file does not need to do anything except exist.
Loading: 0 packages loaded
Loading: 0 packages loaded
iBazel [8:08AM]: Error running Bazel exit status 7

在我看来,这似乎是

的问题
lodd("@npm//:install_bazel_dependencies.bzl", "install_bazel_dependencies")
install_bazel_dependencies()

在我的WORKSPACE 文件中:

workspace(
    name = "examples_angular",
    managed_directories = "@npm": ["node_modules"],
)

load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository")
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

http_archive(
    name = "build_bazel_rules_nodejs",
    sha256 = "2eca5b934dee47b5ff304f502ae187c40ec4e33e12bcbce872a2eeb786e23269",
    urls = ["https://github.com/bazelbuild/rules_nodejs/releases/download/1.4.1/rules_nodejs-1.4.1.tar.gz"],
)

load("@build_bazel_rules_nodejs//:index.bzl", "yarn_install")

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

load("@npm//:install_bazel_dependencies.bzl", "install_bazel_dependencies")

install_bazel_dependencies()

load("@npm_bazel_protractor//:package.bzl", "npm_bazel_protractor_dependencies")

npm_bazel_protractor_dependencies()

load("@npm_bazel_karma//:package.bzl", "npm_bazel_karma_dependencies")

npm_bazel_karma_dependencies()

load("@io_bazel_rules_webtesting//web:repositories.bzl", "web_test_repositories")

web_test_repositories()

load("@io_bazel_rules_webtesting//web/versioned:browsers-0.3.2.bzl", "browser_repositories")

browser_repositories(
    chromium = True,
    firefox = True,
)

load("@npm_bazel_typescript//:index.bzl", "ts_setup_workspace")

ts_setup_workspace()

那我该怎么办呢?


我的BUILD 文件中的devserver 目标:

ts_devserver(
    name = "devserver",
    additional_root_paths = ["src/example"],
    entry_module = "examples_angular/src/main.dev",
    scripts = [
        "@npm//:node_modules/tslib/tslib.js",
        ":rxjs_umd_modules",
        "@npm//date-fns:date-fns.umd.js",
    ],
    static_files = _ASSETS + [
        ":inject_scripts_for_dev",
        "//src/assets",
    ],
    deps = ["//src"],
)

您可以通过克隆:https://github.com/flolu/cents-ideas/tree/3ad56108507ee77f0b8a072e9c204c32d5c9ebdc 并在./services/angular 中运行ibazel run //src:devserver 来重现错误

【问题讨论】:

【参考方案1】:

刚刚检查了你的仓库,这个命令对我很有用。

也许尝试做bazel clean --expunge,然后重复。

【讨论】:

是的,我在我的机器上重新安装了整个 repo,它工作正常。但是您的解决方案也可能会奏效:) 喜欢@Florian:必须完全重新做回购。 bazel clean 不够强。

以上是关于错误加载包'':每个.bzl文件都必须有一个对应的包,但'@npm//:install_bazel_dependencies.bzl'没有的主要内容,如果未能解决你的问题,请参考以下文章

vue打包体积优化之旅

从单个文件同时读取

解决vue项目二次Loading chunk **** failed.

SSIS包中的错误将数据加载到azure数据仓库中

在 UITableView 中缓存图像

TensorFlow的Bazel构建文件结构