[英]Bazel Typescript - Cannot find ts_library Referenced by module_name
我有兩個 Bazel BUILD
文件:
我的目標是將ts_library
從枚舉導入服務器作為服務器ts_library
的依賴ts_library
。 因此,我使用了這里描述的方法: https : //dev.to/lewish/building-a-typescript-monorepo-with-bazel-4o7n (通過module_name
和deps
)
枚舉BUILD
文件:
package(default_visibility = ["//visibility:public"])
load("@io_bazel_rules_docker//nodejs:image.bzl", "nodejs_image")
load("@npm_bazel_typescript//:index.bzl", "ts_library")
ts_library(
name = "enums",
srcs = glob(["src/index.ts"]),
module_name = "@lbm/enums",
)
服務器BUILD
文件:
load("@io_bazel_rules_docker//nodejs:image.bzl", "nodejs_image")
load("@npm_bazel_typescript//:index.bzl", "ts_library")
ts_library(
name = "lib",
srcs = glob(
include = [ "**/*.ts" ],
exclude = [ "src/index.ts" ],
),
deps = ["//enums:enums"]
)
ts_library(
name = "main",
srcs = [ "src/index.ts" ],
deps = ["//enums:enums", ":lib"],
)
filegroup(
name = "libfiles",
srcs = ["lib"],
output_group = "es5_sources",
)
filegroup(
name = "mainfile",
srcs = ["main"],
output_group = "es5_sources",
)
nodejs_image(
name = "server",
data = [
":libfiles",
":mainfile",
],
entry_point = ":mainfile",
)
但是跑步的時候
bazel run //server:server
雖然我已經設置module_name = "@lbm/enums"
並將//enums
添加到deps
,但我收到此錯誤:
INFO: Analyzed target //server:server (0 packages loaded, 0 targets configured).
INFO: Found 1 target...
ERROR: /minimal-bazel-monorepo/server/BUILD:13:1: Compiling TypeScript (devmode) //server:main failed (Exit 1)
server/src/index.ts:2:27 - error TS2307: Cannot find module '@lbm/enums'.
2 import { Constants } from '@lbm/enums';
~~~~~~~~~~~~
Target //server:server failed to build
Use --verbose_failures to see the command lines of failed build steps.
INFO: Elapsed time: 0.207s, Critical Path: 0.09s
INFO: 0 processes.
你可以自己試試: https : //github.com/flolude/minimal-bazel-monorepo
更新 import 語句 from import { Constants } from '@lbm/enums';
import { Constants } from '@lbm/enums/src';
,如Ray 所述,我收到此錯誤:
Error: Cannot find module '@lbm/enums/src/index'. Please verify that the package.json has a valid "main" entry
import { Constants } from '@lbm/enums/src';
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.