简体   繁体   English

反应错误:不允许插件/预设文件导出对象,仅导出功能

[英]error on react: Plugin/Preset files are not allowed to export objects, only functions

I am trying to install new react project but have encountered some issues. 我正在尝试安装新的React项目,但是遇到了一些问题。

Now after resolving many issues, I'm stuck with this issue: 现在,在解决了许多问题之后,我陷入了这个问题:

 ERROR in ./script.jsx
Module build failed (from ./node_modules/babel-loader/lib/index.js):
Error: Plugin/Preset files are not allowed to export objects, only functions. In D:\react_project\node_modules\babel-preset-es2015\lib\index.js

I have encountered this issue after installing @babel/core version 7. 在安装@ babel / core版本7后,我遇到了此问题。

Here's my package.json : 这是我的package.json

{
  "name": "react_project",
  "version": "1.0.0",
  "description": "first project on react",
  "main": "index.js",
  "scripts": {
    "it": "webpack-dev-server --hot"
  },
  "author": "azima",
  "license": "ISC",
  "devDependencies": {
    "@babel/core": "^7.0.0",
    "babel-core": "^6.26.3",
    "babel-loader": "^8.0.1",
    "babel-preset-es2015": "^6.24.1",
    "babel-preset-react": "^6.24.1",
    "webpack": "^4.17.1",
    "webpack-dev-server": "^3.1.7"
  },
  "dependencies": {
    "react": "^16.4.2",
    "react-dom": "^16.4.2",
    "webpack-cli": "^3.1.0"
  }
}

webpack.config.js: webpack.config.js:

var path = require('path');
module.exports = {
    entry: './script.jsx',
    output: {
        path: path.resolve(__dirname,''),
        filename: 'transpiled.js'
    },
    module: {
        rules: [
            {
                test: /\.jsx?$/,
                loaders: 'babel-loader',
                exclude: /node_modules/,
                query: {
                    presets: ['es2015', 'react']
                }   
            }   
        ]
    }
}

What does the error mean and how can I resolve it? 错误是什么意思,我该如何解决?

Sorry I didn't see this question earlier, but here is the problem and the solution for it: "babel-loader": "^8.0.1" works with "@babel/core": "^7.0.0" . 抱歉,我之前没有看到这个问题,但这是问题所在和解决方案: "babel-loader": "^8.0.1""@babel/core": "^7.0.0" Babel 7 moved to scoped packages and introduced some changes in the plugin API, so your problem is you are mixing old and new babel. Babel 7转移到有作用域的软件包,并在插件API中引入了一些更改,因此您的问题是您将新旧Babel混合使用。

babel-preset-es2015 is no longer needed, since there is a @babel/preset-env which takes care of all the new features you may need based on the target platform (see the link for configuration options). 不再需要babel-preset-es2015 ,因为这里有一个@babel/preset-env ,它可以根据目标平台处理您可能需要的所有新功能(请参阅链接以获取配置选项)。

babel-preset-react (which is a babel v6 preset) is now @babel/preset-react (a v7 preset). babel-preset-react (babel v6预设)现在为@babel/preset-react (v7预设)。

And your webpack loader configuration should now look like this: 现在,您的webpack加载器配置应如下所示:

{
    test: /\.jsx?$/,
    loader: 'babel-loader',
    exclude: /node_modules/,
    options: {
        presets: ['@babel/preset-env', '@babel/preset-react']
    }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Babel错误:插件/预设文件不允许导出对象,仅可导出功能 - Babel Error: Plugin/Preset files are not allowed to export objects, only functions 出现“错误:插件/预设文件不允许导出对象,只能导出功能。” 来自 babel-preset-react-app/index.js - Getting "Error: Plugin/Preset files are not allowed to export objects, only functions." from babel-preset-react-app/index.js 错误:插件/预设文件不允许导出对象,只能导出功能/ babel-preset-stage-0 - Error:Plugin /Preset files are not allowed to export objects,only functions/babel-preset-stage-0 Babel Plugin/Preset 文件不允许导出对象,只能导出函数 - Babel Plugin/Preset files are not allowed to export objects, only functions 用graphql开玩笑,“插件/预设文件不允许导出对象,只能导出功能” - Jest with graphql, “Plugin/Preset files are not allowed to export objects, only functions” gulp-babel插件错误:不允许插件/预设文件导出对象,仅导出功能 - Error in plugin gulp-babel: Plugin/Preset files are not allowed to export objects, only functions Babel-Loader Error Plugin/Preset 文件不允许导出对象,只能导出函数 - Babel-Loader Error Plugin/Preset files are not allowed to export objects, only functions “ npm start”抛出错误:不允许插件/预设文件导出对象,仅导出功能 - “npm start” throws Error: Plugin/Preset files are not allowed to export objects, only functions 错误:插件/预设文件不允许导出对象,只能导出功能。 ReactJS - Error: Plugin/Preset files are not allowed to export objects, only functions. ReactJS 使用 JEST 和 Vue.js 失败“插件/预设文件不允许导出对象,只能导出函数。” - Fail with JEST and Vue.js "Plugin/Preset files are not allowed to export objects, only functions."
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM