添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement . We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I am using typescript based react with bun create react.
I did document.getElementById to createRoot in index.tsx.
But I got a lib error with tsconfig.json.

So even though I wrote lib: ['dom', ...] in tsconfig.json , I keep getting Cannot find name 'document'. Do you need to change your target library? Try changing the 'lib' compiler option to include 'dom'. error.

However, changing this error in tsconfig.json to typeRoots: ['bun-types'] instead of type: ['bun-types'] solved the problem.

I think it could be a bun type related error.

index.tsx

import React from "react";
import ReactDOM from "react-dom/client";
import { HelmetProvider } from "react-helmet-async";
import App from "./App";
const targetElement = document.getElementById("root"); // how do i fix this error
const root = ReactDOM.createRoot(targetElement!);
root.render(
  <React.StrictMode>
      <App />
  </React.StrictMode>

tsconfig.json

"compilerOptions": { "allowJs": true, "skipLibCheck": true, "esModuleInterop": true, "strict": true, "forceConsistentCasingInFileNames": true, "resolveJsonModule": true, "isolatedModules": true, "noEmit": true, "allowSyntheticDefaultImports": true, "lib": ["DOM", "DOM.Iterable", "ESNext"], "module": "ESNext", "target": "ESNext", "moduleResolution": "node", "baseUrl": "src", "jsx": "react-jsxdev", "types": ["bun-types"] "include": ["src"]