babel-loader 不工作,意外的标记 '<'

babel-loader not working, Unexpected token '<'

我一直在努力在没有 create-react-app 的情况下设置 React 应用程序。但我一直面临的唯一问题是这个-

ERROR in ./src/index.js 5:16
Module parse failed: Unexpected token (5:16)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
| import App from './comps/App';
|
> ReactDOM.render(<App/>, document.querySelector('#root'));
我在长期搜索中找到的

None 个解决方案解决了这个问题。

似乎 babel-loader 对我不起作用,sass-loader 等任何其他加载程序也不适用。最初我使用的开发依赖是-

babel-loader babel-core babel-preset-env babel-preset-react

后来我用-

替换了这些
babel-loader @babel/core @babel/preset-env @babel/preset-react

但结果相同。请帮我解决问题![​​=18=]

package.json-

{
  "name": "react-webpack-starter",
  "version": "1.0.0",
  "description": "Boilerplate for React apps",
  "main": "index.js",
  "scripts": {
    "start": "webpack-dev-server --mode development --open --hot",
    "build": "webpack --mode production"
  },
  "author": "Sapinder",
  "license": "ISC",
  "dependencies": {
    "react": "^16.13.1",
    "react-dom": "^16.13.1"
  },
  "devDependencies": {
    "@babel/core": "^7.10.5",
    "@babel/preset-env": "^7.10.4",
    "@babel/preset-react": "^7.10.4",
    "babel-loader": "^8.1.0",
    "html-webpack-plugin": "^4.3.0",
    "webpack": "^4.44.0",
    "webpack-cli": "^3.3.12",
    "webpack-dev-server": "^3.11.0"
  }
}

.babelrc-

{
    "presets": ["@babel/preset-env", "@babel/preset-react"]
}

webpack.config.js-

const path = require('path');
const HTMLWebpackPlugin = require('html-webpack-plugin');

module.export = {
    entry: './src/index.js',
    output: {
        path: path.join(__dirname, '/dist'),
        filename: 'index_bundle.js'
    },
    module: {
        rules: [
            {
                test: /\.js$/,
                exclude: /node_modules/,
                use: {
                    loader: 'babel-loader'
                }
            }
        ]
    },
    plugins: [
        new HTMLWebpackPlugin({
            template: './src/index.html'
        })
    ]
}

我们来试试

// webpack.config.js

...

module.exports = {...};

...

请注意您的示例中 module.export 中缺少的“s”:D