Use Bun.build
to transpile a single file
#8335
-
Hi, I am looking at I came up with this code: const result = await Bun.build({
entrypoints: ['./test/Test.tsx'],
sourcemap: 'inline',
});
if (!result.success) {
for (const item of result.logs) {
console.log(item);
}
process.exit(1);
}
if (result.logs.length > 0) {
throw new Error('Expected no logs, got ' + result.logs.length);
}
if (result.outputs.length !== 1) {
throw new Error('Expected 1 output, got ' + result.outputs.length);
}
if (result.outputs[0].kind !== 'entry-point') {
throw new Error('Expected output kind to be "entry-point", got ' + result.outputs[0].kind);
}
if (result.outputs[0].sourcemap !== null) {
throw new Error('Expected output sourcemap to be null, got ' + result.outputs[0].sourcemap);
}
console.log(await result.outputs[0].text()); The file at import NonExistent from './NonExistent';
export default function Test() {
return (
<div>TEST</div>
);
} When I run my code, I get this error:
This only happens when there is TSX/JSX in the test file. I found this config option: // test/Test.tsx
import {
jsxDEV
} from "react/jsx-dev-runtime";
function Test() {
return jsxDEV("div", {
children: "TEST"
}, undefined, false, undefined, this);
}
export {
Test as default
}; Looks like I missed this news: https://legacy.reactjs.org/blog/2020/09/22/introducing-the-new-jsx-transform.html Is there any way to remove the import that was automatically added? I don't really care what the I also added |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Found the answer: const transpiler = new Bun.Transpiler({ loader: 'tsx', tsconfig: { compilerOptions: { jsx: 'react' } } });
const typeScript = await Bun.file('./test/Test.tsx').text();
const javaScript = await transpiler.transform(typeScript);
console.log(javaScript); |
Beta Was this translation helpful? Give feedback.
Found the answer: