aspect-build / aspect-build/rules_ts
[Bug]: Cannot find .ts source file when using source_map = True
- Dominant language
- Starlark
- Stars
- 138
- Forks
- 87
- Avg merge
- 2d 8h
- Merged PRs (30d)
- 3
Description
### What happened?
I'm attempting to use the output of `ts_project` in the `data` attribute of `js_run_devserver`, ex:
```
ts_project(
name = "foo",
srcs = ["foo.ts"],
source_map = True,
declaration = True,
)
js_run_devserver(
name = "serve_foo",
data = [":foo"]
)
```
With above config, it produces output files like
```
foo.js
foo.js.map
foo.d.ts
```
Where `foo.js.map` has
```
{"version":3,"file":"foo.js","sourceRoot":"","sources":["foo.ts"],"names":[],"mappings":"all the mappings"}
```
notably, the `sources: ["foo.ts"]`. However, the `foo.ts` file is not in the output files in the `js_run_devserver` sandbox which leads to a warning in the console when running the devserver like
```
WARNING in ./src/foo.js
Module Warning (from /home/name/.cache/bazel/_bazel_name/b2adc1b3e500b13859103a758c7a696d/execroot/__main__/bazel-out/k8-fastbuild/bin/src/app.sh.runfiles/__main__/node_modules/.aspect_rules_js/source-map-loader@0.2.4/node_modules/source-map-loader/index.js):
(Emitted value instead of an instance of Error) Cannot find source file 'foo.ts': Error: Can't resolve './foo.ts' in '/tmp/js_run_devserver-YsBSjK/__main__/src/utils/importsFoo'
@ ./src/utils/importsFoo.js 20:21-46
```
The application seems to build and run as normal despite the warning. If changed to `source_map = False`, the warning goes away.
### Version
Development (host) and target OS/architectures: `ubuntu_bionic`
Output of `bazel --version`: `bazel 5.3.1-1`
Version of the Aspect rules, or other relevant rules from your
`WORKSPACE` or `MODULE.bazel` file:
```
rules_js: 1.8.1
rules_ts: 1.0.5
```
Language(s) and/or frameworks involved:
### How to reproduce
```shell
Pass `ts_project` output as `data` to `js_run_devserver`.
```
### Any other information?
Apologies for the minimal reproduction steps, still fairly new to Bazel so wasn't sure how to package up related workspace files for a minimal example (typically I'd link a codesandbox but wasn't sure what the equivalent was here). Happy to provide any additional information, files, or reproduction steps.
Contributor guide
Research direction
Reproduce the configuration that passes ts_project output with source_map = True to js_run_devserver through the documented shell steps. Inspect the generated .js.map sources entry and the files available in the devserver sandbox; done means the devserver no longer warns that foo.ts cannot be resolved while source maps remain enabled.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- build-system
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100