包裹React如何修复设置错误?

发布于 2025-02-05 19:22:00 字数 2419 浏览 1 评论 0原文

我运行包裹/ React项目时我的index.js文件,

我一直在下面遇到错误

@parcel/transformer-js:意外令牌。期望这个,导入,异步,功能,[对于数组 文字,{for object @ @ for Decorator,function,class,null,null,true,false,数字, bigint,string,regexp,`for template for template,(或标识符

  import { createRoot } from 'react-dom/client';
    import App from './App/App';
    
    
    const container = document.getElementById('root');
    
    const root = createRoot(container); 
    // createRoot(container!) if you use TypeScript
    root.render(<App/>);

//index.html文件

<!doctype html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initialscale=1.0">
    <link href="./index.css" rel="stylesheet">
    <title>
        My App
    </title>
</head>

<body>
    <div id="root">

    </div>
    <script type="module" src="./index.js">
    </script>
    </body>

</html>

///我的app.js文件在下面

  export default function App() {
  return (
    <div className=''>
        <h2 className='text-green-700 '>
Analytics
        </h2>
    </div>
  )
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/16.6.3/umd/react.production.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/16.6.3/umd/react-dom.production.min.js"></script>

我的包装文件

{
    "devDependencies": {
        "parcel": "2.4",
        "postcss": "^8.4.14",
        "tailwindcss": "^3.0.24"
    },
    "dependencies": {
        "react-google-charts": "^4.0.0"
    },
    "name": "analytics",
    "version": "1.0.0",
    "description": "Analytic app",
    "source": "src/index.html",
    "main": "index.js",
    "scripts": {
        "start": "parcel",
        "build": "parcel build"
    },
    "author": "Caldewood Alikula",
    "license": "ISC"
}

my index.js file

When i run a parcel/ react project i keep getting the error below

@parcel/transformer-js: Unexpected token ). Expected this, import, async, function, [ for array
literal, { for object literal, @ for decorator, function, class, null, true, false, number,
bigint, string, regexp, ` for template literal, (, or an identifier

  import { createRoot } from 'react-dom/client';
    import App from './App/App';
    
    
    const container = document.getElementById('root');
    
    const root = createRoot(container); 
    // createRoot(container!) if you use TypeScript
    root.render(<App/>);

//index.html file

<!doctype html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initialscale=1.0">
    <link href="./index.css" rel="stylesheet">
    <title>
        My App
    </title>
</head>

<body>
    <div id="root">

    </div>
    <script type="module" src="./index.js">
    </script>
    </body>

</html>

/// my app.js file is below

  export default function App() {
  return (
    <div className=''>
        <h2 className='text-green-700 '>
Analytics
        </h2>
    </div>
  )
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/16.6.3/umd/react.production.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/16.6.3/umd/react-dom.production.min.js"></script>

my package.json file

{
    "devDependencies": {
        "parcel": "2.4",
        "postcss": "^8.4.14",
        "tailwindcss": "^3.0.24"
    },
    "dependencies": {
        "react-google-charts": "^4.0.0"
    },
    "name": "analytics",
    "version": "1.0.0",
    "description": "Analytic app",
    "source": "src/index.html",
    "main": "index.js",
    "scripts": {
        "start": "parcel",
        "build": "parcel build"
    },
    "author": "Caldewood Alikula",
    "license": "ISC"
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦回梦里 2025-02-12 19:22:00

避免通过cdn包括reactreact-dom

  1. 将它们以npm软件包的方式安装:
npm i [email protected]
npm i [email protected]
  1. 重新启动服务器

Avoid include react and react-dom via CDN.

  1. Install them as npm packages:
npm i [email protected]
npm i [email protected]
  1. Restart the server
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文