My current challenge involves importing a JSON file from TypeScript while utilizing the resolveJsonModule
flag in my tsconfig. The problem lies in how I can provide this JSON file to ts_library
since it seems unable to locate the file. This issue extends to other non-.ts
and .tsx
files such as a .env
.
For instance, consider this snippet of a ts_library
within a BUILD.bazel
file:
ts_library(
name = "src",
srcs = glob(["*.ts"]),
deps = [
"@npm//:node_modules",
]
)
accompanied by an index.ts
like so:
import test from './test.json';
console.log(test);
and also a test.json
with the content:
{
"foo": "bar"
}
This setup triggers the following error message:
index.ts:1:18 - error TS2307: Cannot find module './test.json'.
I suspect that I need to somehow include the JSON file in the deps
section of my rule. However, I am unsure how to go about it given that deps
does not accept direct file references like //:test.json
.