Skip to content

When saving a .ts asset as text, it gets executed in the browser #23299

@TNTSuperMan

Description

@TNTSuperMan

What version of Bun is running?

1.2.23+cf1367137

What platform is your computer?

Linux 6.6.87.2-microsoft-standard-WSL2 x86_64 x86_64

What steps can reproduce the bug?

1. Prepare the following files

asset.ts

console.error("Unreachable!");

frontend.ts

//@ts-ignore
import code from "./asset.ts" with { type: "text" };

console.log(code);

index.html

<!DOCTYPE html>
<html>
  <head>
    <script src="frontend.ts"></script>
  </head>
  <body></body>
</html>

index.ts

import index from "./index.html";

export default {
  routes: {
    "/*": index
  },
  fetch() {}
}

2. Run bun run index.ts
3. Open localhost:3000 in browser
4. Save asset.ts

What is the expected behavior?

The following content should be displayed in the DevTools console.

console.error("Unreachable!");

What do you see instead?

The following will be displayed on the DevTools console.

Unreachable!
undefined

Additional information

I have previously created an issue that may be related.

#23260

And it's just my thought, but the loader in asset.ts might have changed from text to ts after saving.
This could explain why the file is unexpectedly executed in the browser.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions