【问题标题】:Parcel React How do i fix the set up error?Parcel React 如何修复设置错误?
【发布时间】:2022-11-25 06:26:02
【问题描述】:

我的 index.js 文件

当我运行包裹/反应项目时,我不断收到以下错误

@parcel/transformer-js:意外的标记)。预期这个,导入,异步,函数,[ 用于数组 文字,{ 对象文字,@ 装饰器,函数,类,null,true,false,数字, bigint、字符串、正则表达式、用于模板文字的`、( 或标识符

  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>

我的 package.json 文件

{
    "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"
}

【问题讨论】:

标签: reactjs tailwind-css parceljs


【解决方案1】:

避免通过 CDN 包含 reactreact-dom

  1. 将它们安装为npm 包:
    npm i react@16.6.3
    npm i react-dom@16.6.3
    
    1. 重启服务器

【讨论】:

    猜你喜欢
    • 2023-03-31
    • 2020-02-21
    • 2019-11-23
    • 1970-01-01
    • 2019-09-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-08-01
    相关资源
    最近更新 更多