[英]bazel: '@bazel/typescript' is not a package
My attempt loading ts_project
fails with the error message below:我尝试加载
ts_project
失败并显示以下错误消息:
ERROR: error loading package '': Label '@npm//@bazel/typescript:index.bzl' is invalid because '@bazel/typescript' is not a package; perhaps you meant to put the colon here: '@npm//:@bazel/typescript/index.bzl'?
WORKSPACE
: WORKSPACE
:
workspace(
name = "nodejs",
managed_directories = {"@npm": ["node_modules"]},
)
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
http_archive(
name = "build_bazel_rules_nodejs",
sha256 = "cfc289523cf1594598215901154a6c2515e8bf3671fd708264a6f6aefe02bf39",
urls = ["https://github.com/bazelbuild/rules_nodejs/releases/download/4.4.6/rules_nodejs-4.4.6.tar.gz"],
)
load("@build_bazel_rules_nodejs//:index.bzl", "npm_install")
npm_install(
name = "npm",
package_json = "//:package.json",
package_lock_json = "//:package-lock.json",
)
BUILD
: BUILD
:
load("@npm//@bazel/typescript:index.bzl", "ts_project")
load("@build_bazel_rules_nodejs//:index.bzl", "nodejs_test")
ts_project(
name = "lib",
srcs = glob(["src/**/*.ts"]),
tsconfig = "tsconfig.json",
deps = [
"@npm//@types/lodash"
],
declaration = True,
source_map = True,
)
nodejs_test(
name = "index_test",
entry_point = ":src/index.ts",
data = [
"@npm//lodash",
":lib"
],
)
What's wrong?怎么了?
Let's say you have a minimal package.json that you're not showing us here, say假设你有一个最小的 package.json 你没有在这里展示给我们,比如说
{
"name": "test",
"version": "1.0.0"
}
Then if you check what's in @npm
, you will see that there are no packages defined inside of it.然后,如果您检查
@npm
中的内容,您将看到其中没有定义任何包。
❯ bazel query @npm//...
@npm//:node_modules
Loading: 1 packages loaded
You'll need to add @bazel/typescript
to your package.json to have npm_install
make it available to you.您需要将
@bazel/typescript
添加到 package.json 以使npm_install
对您可用。 So run所以运行
❯ npm install @bazel/typescript
up to date, audited 25 packages in 644ms
found 0 vulnerabilities
package.json now has package.json 现在有
{
"name": "test",
"version": "1.0.0",
"dependencies": {
"@bazel/typescript": "^4.4.6"
}
}
and our Bazel query now shows a bunch of available packages:我们的 Bazel 查询现在显示了一堆可用的包:
❯ bazel query @npm//...
@npm//tsutils:tsutils__umd
@npm//tsutils:tsutils__typings
@npm//tsutils:tsutils__all_files
[...]
@npm//@bazel/typescript:typescript__nested_node_modules
@npm//@bazel/typescript:typescript__files
Loading: 0 packages loaded
including the one that the load
statement was previously not finding.包括
load
语句以前没有找到的那个。 At this point you can try to build your package again, making sure to add all the dependencies you need (like lodash).此时,您可以尝试再次构建您的 package,确保添加您需要的所有依赖项(如 lodash)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.