oven-sh / bun

Incredibly fast JavaScript runtime, bundler, test runner, and package manager – all in one
https://bun.sh
Other
73.09k stars 2.67k forks source link

TypeScript syntax doesn't work in BunPlugin #12548

Open huseeiin opened 2 months ago

huseeiin commented 2 months ago

What version of Bun is running?

1.1.18+5a0b93523

What platform is your computer?

Linux 6.5.0-18-generic x86_64 x86_64

What steps can reproduce the bug?

when creating a virtual module (https://bun.sh/docs/runtime/plugins#virtual-modules)

Bun.plugin({
  setup(build) {
    build.module('hi', () => ({
      contents: 'import { type TSchema } from \'@sinclair/typebox\'',
      loader: 'ts',
    }))
  },
})

console.log(require('hi'))

What is the expected behavior?

it works with "tsx" even though I'm not writing jsx:

Bun.plugin({
  setup(build) {
    build.module('hi', () => ({
      contents: 'import { type TSchema } from \'@sinclair/typebox\'',
      loader: 'tsx',
    }))
  },
})

console.log(require('hi'))

What do you see instead?

1 | import { type TSchema } from '@sinclair/typebox'
                  ^
error: Expected "}" but found "TSchema"
    at hi:1:15

1 | import { type TSchema } from '@sinclair/typebox'
                          ^
error: Expected "from" but found "}"
    at hi:1:23

Additional information

No response

shpaw415 commented 1 month ago

Same error but insted i used jsx syntax and js loader to make it work.