Skip to content

[Bug]: Cannot find .ts source file when using source_map = True #338

@johnharringt0n

Description

@johnharringt0n

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

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinghelp wantedAspect isn't prioritizing this, but the community couldneed: fundingWe could prioritize this based on donation to https://opencollective.com/aspect-build

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions