aspect-build / aspect-cli

correct, fast, usable: choose three
https://aspect.build/cli
Apache License 2.0
93 stars 22 forks source link

[Bug]: Index out of range error due to ViteJS public import #680

Closed Juricakov closed 5 months ago

Juricakov commented 7 months ago

What happened?

Running JS Gazelle results in an index out of range error when a vite public imports exist in file. See https://vitejs.dev/guide/assets#the-public-directory

You should always reference public assets using root absolute path - for example, public/icon.png should be referenced in source code as /icon.png.

Removing any such imports, ie import viteLogo from '/vite.svg' fixes the problem.

Version

MacOS, Bazel 6.4.0, CLI v5.9.25

How to reproduce

- Bootstrap a new vite project using `npm create vite@latest`
- Run Gazelle

Any other information?

panic: runtime error: index out of range [0] with length 0

goroutine 1 [running]:
aspect.build/cli/gazelle/js.(*Resolver).resolvePackage(0x14000122140, {{0x0, 0x0}, {0x14001d7a870, 0x2d}, {0x14001d01b67, 0x3}, 0x0}, {0x140016a00b0?, 0x104c75444?})
    external/build_aspect_cli/gazelle/js/resolve.go:352 +0x314
aspect.build/cli/gazelle/js.(*Resolver).resolveModuleDep(0x14000122140, 0x14001c29e00, 0x4ae0?, {{{0x1050f7b7f, 0x2}, {0x140016a00b0, 0x9}}, {0x105ba38e0, 0x0, 0x0}, ...}, ...)
    external/build_aspect_cli/gazelle/js/resolve.go:336 +0x3f8
aspect.build/cli/gazelle/js.(*Resolver).resolveModuleDeps(0x105857f90?, 0x14001c29e00, 0x14003709148?, 0x14000a10848, {{0x0, 0x0}, {0x14001d7a870, 0x2d}, {0x14001d01b67, 0x3}, ...})
    external/build_aspect_cli/gazelle/js/resolve.go:217 +0x298
aspect.build/cli/gazelle/js.(*Resolver).Resolve(0x140037091f8?, 0x1050c2fac?, 0x0?, 0x0?, 0x14000e21d80, {0x1057c1d40?, 0x14000a10858}, {{0x0, 0x0}, {0x14001d7a870, ...}, ...})
    external/build_aspect_cli/gazelle/js/resolve.go:188 +0x27c
main.runFixUpdate({0x1400002425a, 0x22}, 0x16b19b231?, {0x1400013e010, 0x0, 0x0})
    external/bazel_gazelle/cmd/gazelle/fix-update.go:442 +0x14f0
main.run({0x1400002425a?, 0x22?}, {0x1400013e010?, 0x1?, 0x1?})
    external/bazel_gazelle/cmd/gazelle/gazelle.go:95 +0x20c
main.main()
    external/bazel_gazelle/cmd/gazelle/gazelle.go:72 +0x104
jbedard commented 5 months ago

@Juricakov I think this has been fixed, if not already then in the next release after some refactoring I did to the method the crash was in. If you can give it a shot on the next release please let me know if you still see the issue.