Closed awilderink closed 1 year ago
await Bun.build({
entrypoints: ['./src/index.tsx'],
outdir: './dist',
target: 'bun',
})
Same issue for me using a build.ts
file and bun build.ts
I found the issue. @kitajs/html
is imported through require
statements. This should be fine, but bun
probably builds this wrong (maybe an issue should be created but I'm not sure how to describe it). You can fix it by swapping the require
statement for import
s. I want to submit a PR but the repo won't let me.
Here are the changes
// index.ts
...
import { createElement, Fragment as F } from '@kitajs/html'
globalThis.ElysiaJSX = createElement
// @ts-ignore
globalThis.ElysiaJSX.Fragment = Fragment
export const Fragment = F as unknown as Component
export default html
...
and
// declaration.ts
// remove all of the following since they have been moved to index.ts (imports in declaration files will make them not globally available, see https://stackoverflow.com/a/51114250)
// @ts-ignore
const { createElement, Fragment } = require('@kitajs/html')
// @ts-ignore
globalThis.ElysiaJSX = createElement
// @ts-ignore
globalThis.ElysiaJSX.Fragment = Fragment
Hey @awilderink. After this change, does this problem still occurs?
Seems to be a issue with CJS syntax when using the bun bundler: https://github.com/oven-sh/bun/issues/5654
Does it have any workaround at the moment?
I'm releasing a fix for @kitajs/html asap. But it will keep incompatibilities with https://github.com/elysiajs/elysia/issues/178.
If you build a project with
bun
using this package, you can't run the built file.How to reproduce
elysia
and theelysia-html
plugin.This could also be an issue with
bun build
or@kitajs/html
.