[英]Fail to import typescript module built from bazel
I try to build a node module using @bazel/typescript and npm_package rules of bazel using bazel build //core:package
. 我尝试使用
bazel build //core:package
使用@ bazel / typescript和bpmel的npm_package规则构建节点模块。 Below is my BUILD file 下面是我的BUILD文件
package(default_visibility = ["//visibility:public"])
load("@npm_bazel_typescript//:index.bzl", "ts_library")
load("@build_bazel_rules_nodejs//:defs.bzl", "npm_package")
ts_library(
name = "core",
srcs = glob(["*.ts"]),
)
npm_package(
name = "package",
srcs = ["package.json"],
deps = [":core"],
replacements = {"//internal/": "//"},
)
Then I run bazel run //core:package.pack
and it generates a .tgz
file and I install this module by running npm install ./xxx.tgz -s
. 然后我运行
bazel run //core:package.pack
并生成一个.tgz
文件,我通过运行npm install ./xxx.tgz -s
安装这个模块。 Everything works well until I try to import this module using import * as core from 'core';
一切顺利,直到我尝试使用
import * as core from 'core';
导入此模块import * as core from 'core';
It gives me error says Error: Cannot find module 'core/index'
它给我错误说
Error: Cannot find module 'core/index'
The declaration files of the module looks like this 模块的声明文件如下所示
/// <amd-module name="core/index" />
export * from './public_api';
/// <amd-module name="core/public_api" />
export declare const foo = "foo";
export declare const bar = "bar";
My questions are: 我的问题是:
Please help!!! 请帮忙!!!
Okay, I find the answer myself. 好的,我自己找到了答案。 From ts_library doc, it does not explain and list an example to use a parameter called
从ts_library doc,它没有解释和列出使用被调用参数的示例
module_name
If you do not pass this parameter when you try to build a module , it will make the file path as the module name which will cause importing issues. 如果在尝试构建模块时未传递此参数,则会将文件路径作为模块名称,这将导致导入问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.