ReferenceError:未知选项:.present

ili*_*lia 2 reactjs webpack babeljs

你好,我刚刚为 React JS 设置了环境,它给了我错误 ReferenceError: Unknown option: .present. ,这里是.babelrc webpack.config.js,package.jsonreact.js(文件)的代码

.babelrc

{
  "presets": [
    "@babel/preset-env",
    "@babel/preset-react"
  ]
}
Run Code Online (Sandbox Code Playgroud)

webpack.config.js :

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

module.exports = {
entry: './react.js',
output:{
    path: path.join(__dirname, '/frapp'),
    filename: 'bundled.js'
},
devServer:{
    inline: true,
    port: 8001
},
module: {
    rules: [
        {
           test: /\.jsx?$/,
           exclude: /node_modules/,
           loader: 'babel-loader',
           query:{
             present:['es2015', 'react']
           }
        }
    ]
},
  plugins: [
    new HtmlWebpackPlugin({
        template: './index.html'
    })
  ]
}
Run Code Online (Sandbox Code Playgroud)

包.json:

{
  "name": "reacc",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "start": "webpack-dev-server --mode development --open --hot",
    "build": "webpack --mode production"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "@babel/core": "^7.2.2",
    "@babel/preset-env": "^7.3.1",
    "@babel/preset-react": "^7.0.0",
    "babel-loader": "^8.0.5",
    "html-webpack-plugin": "^3.2.0",
    "react": "^16.8.1",
    "react-dom": "^16.8.1",
    "webpack": "^4.29.3",
    "webpack-cli": "^3.2.3",
    "webpack-dev-server": "^3.1.14"
  }
}
Run Code Online (Sandbox Code Playgroud)

有关更多详细信息,我想在这里截取我的目录的屏幕截图 图像

这是错误的一部分:模块构建失败(来自./node_modules/babel-loader/lib/index.js):ReferenceError:未知选项:.present。 有关选项的更多信息,请查看https://babeljs.io/docs/en/babel-core/#options 。

事实上,react打开html页面但不显示div中的文本

jay*_*rjo 7

presets不是present:['es2015', 'react']。你的 中有一个错字webpack.config.js

还有那把钥匙是什么query

query: {
   present:['es2015', 'react']
}
Run Code Online (Sandbox Code Playgroud)

据我所知应该是这样options。所以:

options: {
   presets: ['es2015', 'react']
}
Run Code Online (Sandbox Code Playgroud)