2

I try to build a node module using @bazel/typescript and npm_package rules of bazel using bazel build //core:package. Below is my BUILD file

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. Everything works well until I try to import this module using import * as core from 'core';

It gives me error says 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:

  1. it is not able to imported because it is a amd module?
  2. how to I resolve this issue?

Please help!!!

eded
  • 3,778
  • 8
  • 28
  • 42

1 Answers1

0

Okay, I find the answer myself. From ts_library doc, it does not explain and list an example to use a parameter called

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.

eded
  • 3,778
  • 8
  • 28
  • 42