Open pinkboid opened 1 year ago
Facing this problem, too
Facing this problem, too
It looks like it can be fixed with bun add react
. The docs probably should mention that as a required dependency, but makes sense.
Thanks @pinkboid - it looks like I still get the same error messaging though on my JSX.
Doesn't seem very "out of the box" yet :')
Thanks @pinkboid - it looks like I still get the same error messaging though on my JSX.
Ah looks like bun add @types/react
is also required. Adding both just fixed mine.
Doesn't seem very "out of the box" yet :')
These were my thoughts too.
This worked 🥳 I did also need to update my tsconfig to "jsx": "react-jsx"
Have you been able to render your JSX on the DOM, @pinkboid ? on a localhost server
Have you been able to render your JSX on the DOM, @pinkboid ? on a localhost server
Working on it. Trying to implement the basic example
import * as ReactDOM from 'react-dom/client'
import { Component } from "./Component.tsx"
const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(<Component message="Sup!" />)
but am getting the error in vscode
Cannot find name 'document'. Do you need to change your target library? Try changing the 'lib' compiler option to include 'dom'.ts(2584)
any
despite my tsconfig already having
{
"compilerOptions": {
"lib": ["ESNext", "dom"],
not sure...
This is exactly where I'm at now. Have hit a brick wall. Will revert back here if I am successful!
I looked at react-ts-template-for-bun
but it omits Bun types from the config
https://github.com/itsanji/react-ts-template-for-bun/blob/master/tsconfig.json
Edit* Yup, doesn't use Bun.serve()
This is exactly where I'm at now. Have hit a brick wall. Will revert back here if I am successful!
I looked at
react-ts-template-for-bun
but it omits Bun types from the confighttps://github.com/itsanji/react-ts-template-for-bun/blob/master/tsconfig.json
Edit* Yup, doesn't use
Bun.serve()
So it looks like we are supposed to bundle the index.tsx
into a out/
directory using bun build index.ts --outdir out/
, manually create a index.html
inside of out/
with the <script>
tag linking to ./index.js
, and then run bunx serve out/
. This should get a web server spinning with the react component rendered to the DOM, but it doesn't fix the IDE alert about cannot find name document
..
Also, it just actually doesn't work when I spin up the web server. I'm getting
Loading module from “http://localhost:3000/index.js” was blocked because of a disallowed MIME type (“text/html”).
in the console.log
Maybe I missed a step, will go back and read again. Definitely not feeling like "it just works"... haha
After some digging on bun discord, I came across this thread from this morning:
"Vite it the best option for this. Frontend hot reloading requires a full dev server that stitches together the bundler, module loader, HTTP/WebSocket server, etc. Bun provides the component parts but doesn't try to be a dev server that works out of the box (yet) With React in particular, hot reloading requires a package called react-fast-refresh getting injected during bundling which isn't something Bun does currently. We're working on a "Framework API" (currently marked as "Coming Soon" in the sidebar of the documentation) that will make something like this possible with just Bun"
From Colin in DevRel @ bun
Sounds like, until these bits are stitched together, we may still need to use Vite.
To access document
, you currently need to add:
/// <reference lib="dom" />
/// <reference lib="dom.iterable" />
To the typescript file itself. See here: https://bun.sh/docs/runtime/typescript
This didn't seem to help me get a Hello World rendering though!
bun add react react-dom
bun add -D @types/react @types/react-dom
But I still getting message
<NoName message="Hello world!" />
instead of compiled
What version of Bun is running?
1.0.0+822a00c4d508b54f650933a73ca5f4a3af9a7983
What platform is your computer?
Darwin 22.3.0 arm64 arm
What steps can reproduce the bug?
react.tsx
What is the expected behavior?
No VSCode Intellisense errors, can run
What do you see instead?
VSCode Intellisense errors, can't run
Additional information
tsconfig.json
package.json