mirror of
https://github.com/oven-sh/bun
synced 2026-02-16 13:51:47 +00:00
Fix the crash when importing a module that does not exist. (#4348)
Close: #4240
This commit is contained in:
@@ -1818,6 +1818,12 @@ pub const PackageManager = struct {
|
||||
else => |pkg_id| pkg_id,
|
||||
};
|
||||
|
||||
if (resolution_id == invalid_package_id) {
|
||||
return .{
|
||||
.not_found = {},
|
||||
};
|
||||
}
|
||||
|
||||
return .{
|
||||
.resolution = .{
|
||||
.resolution = this.lockfile.packages.items(.resolution)[resolution_id],
|
||||
|
||||
@@ -234,3 +234,25 @@ for (const entry of await decompress(Buffer.from(buffer))) {
|
||||
]);
|
||||
expect(await exited2).toBe(0);
|
||||
});
|
||||
|
||||
it("should not crash when downloading a non-existent module, issue#4240", async () => {
|
||||
await writeFile(
|
||||
join(run_dir, "test.js"),
|
||||
`
|
||||
import { prueba } from "pruebadfasdfasdkafasdyuif.js";
|
||||
`,
|
||||
);
|
||||
const { exited: exited } = spawn({
|
||||
cmd: [bunExe(), "test.js"],
|
||||
cwd: run_dir,
|
||||
stdin: null,
|
||||
stdout: "pipe",
|
||||
stderr: "pipe",
|
||||
env: {
|
||||
...env,
|
||||
BUN_INSTALL_CACHE_DIR: join(run_dir, ".cache"),
|
||||
},
|
||||
});
|
||||
// The exit code will not be 1 if it panics.
|
||||
expect(await exited).toBe(1);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user