首页 > 解决方案 > 如何解决 React 中的意外令牌 (<) 错误?

问题描述

与本教程相关:https ://www.youtube.com/watch?v=GieYIzvdt2U 我收到错误:

    ERROR in ./leadmanager/frontend/scr/components/App.js 6:15
    Module parse failed: Unexpected token (6:15)
    You may need an appropriate loader to handle this file type.
    | class App extends Component {
    |     render() {
    >         return <h1>React App</h1>
    |     }
    | }
     @ ./leadmanager/frontend/scr/index.js 1:0-35

当我跑步时 npm run dev

您可以在https://github.com/bewaresandman/django上找到我的代码

我很确定我的代码与教程中的代码完全一致,所以我很困惑。

编辑

.babelrc 和 webpack.config.js 文件位于错误的文件夹中。我修好了。没有错误:发生 ERROR in ./leadmanager/frontend/scr/components/App.js Module build failed (from ./node_modules/babel-loader/lib/index.js): SyntaxError: C:\Users\meissners\eclipse-workspace\django\leadmanager\frontend\scr\components\App.js: Unexpected token (6:15)

标签: javascriptreactjswebpack

解决方案


你应该使用jsx文件。

用and重命名你的index.jsand 。App.jsindex.jsxApp.jsx


推荐阅读