英文:
Uncaught SyntaxError: missing ) after argument list in React
问题
I used vite for creating a React-typescript project, and I got a blank page with the error :
Uncaught SyntaxError: missing ) after argument list (at main.tsx:6:51)
in main.tsx :
import React from "react";
import ReactDOM from "react-dom/client";
import App from "./App.tsx";
import "./index.css";
ReactDOM.createRoot(document.getElementById("root") as HTMLElement).render(
<React.StrictMode>
<App />
</React.StrictMode>
);
the error has explained in :
But it's not similar to my problem
英文:
I used vite for creating a React-typescript project, and I got a blank page with the error :
Uncaught SyntaxError: missing ) after argument list (at main.tsx:6:51)
in main.tsx :
import React from "react";
import ReactDOM from "react-dom/client";
import App from "./App.tsx";
import "./index.css";
ReactDOM.createRoot(document.getElementById("root") as HTMLElement).render(
<React.StrictMode>
<App />
</React.StrictMode>
);
the error has explained in :
But it's not similar to my problem
答案1
得分: 0
根据错误位置,似乎可能是因为 Typescript 配置不正确。如果尚未尝试过,请尝试使用 Vite 的 "create" 脚本之一来设置项目,如 https://vitejs.dev/guide/#scaffolding-your-first-vite-project 中所示,
yarn create vite my-app --template react-ts
确保像上面示例中那样选择一个 Typescript 模板,比如 react-ts。
英文:
Given the location of the error, seems it could be due to having Typescript improperly set up. If you haven't already, try using one of Vite's "create" scripts to set up the project as show in https://vitejs.dev/guide/#scaffolding-your-first-vite-project,
yarn create vite my-app --template react-ts
Make sure to select a Typescript template such as react-ts in the example above.
答案2
得分: -1
It seems that you're using an incorrect import statement for the ReactDOM module. Instead of importing from "react-dom/client", you should import from "react-dom". I've never seen that kind of import ever.
Here's the corrected code:
import React from "react";
import ReactDOM from "react-dom";
import App from "./App.tsx";
import "./index.css";
ReactDOM.createRoot(document.getElementById("root") as HTMLElement).render(
<React.StrictMode>
<App />
</React.StrictMode>
);
Make sure to update the import statement for ReactDOM, and try running your project again. This should resolve the "missing ) after argument list" error and render your React app correctly.
Hope this works!
英文:
It seems that you're using an incorrect import statement for the ReactDOM module. Instead of importing from "react-dom/client", you should import from "react-dom". I've never seen that kind of import ever.
Here's the corrected code:
import React from "react";
import ReactDOM from "react-dom";
import App from "./App.tsx";
import "./index.css";
ReactDOM.createRoot(document.getElementById("root") as
HTMLElement).render(
<React.StrictMode>
<App />
</React.StrictMode>
);
Make sure to update the import statement for ReactDOM, and try running your project again. This should resolve the "missing ) after argument list" error and render your React app correctly.
Hope this works!
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论