Preset files are not allowed to export objects

前端 未结 10 978
梦如初夏
梦如初夏 2020-11-30 01:18

I have a carousel file in which I want to get index.js and build block.build.js, so my webpack.config.js is:



        
相关标签:
10条回答
  • 2020-11-30 02:09

    There are upgrades in babel 7 from version 6 refer to https://babeljs.io/docs/en/v7-migration. To solve the current problem/error

    Install

    npm install --save-dev @babel/preset-react
    
    npm install --save-dev @babel/preset-env
    

    then in .babelrc the dependency for presets should look like

    {
    
    "presets":["@babel/preset-env", "@babel/preset-react"],
    
       "plugins": [
        "react-hot-loader/babel", "transform-object-rest-spread"]
    
    }
    
    0 讨论(0)
  • 2020-11-30 02:10

    I had "stage-1" within my presets in .babelrc, so I removed that and the error went away

    0 讨论(0)
  • 2020-11-30 02:11

    That is due to outdated babel packages being used. The babel project, just like most other active Javascript projects, have moved on to using scope packages. Hence, the package names starts with @babel

    If you are using yarn, follow the below one:

    Step 1: Remove the old packages

    $ yarn remove babel-core babel-loader babel-preset-env babel-preset-react
    

    step 2: Add the new packages

    $ yarn add -D @babel/core babel-loader @babel/preset-env @babel/preset-react
    

    If you are using npm, follow the below one:

    step 1: Remove the old packages

    $ npm uninstall babel-core babel-loader babel-preset-env babel-preset-react
    

    step 2: Add the new packages

    $ npm add -D @babel/core babel-loader @babel/preset-env @babel/preset-react
    

    Step 3: common to both npm or yarn

    After installing the newer packages, remember to update your .babelrc presets from react to @babel/preset-react. Here is a simple example

    {
    "presets": [
    "@babel/preset-env",
    "@babel/preset-react"
    ]
    }
    
    0 讨论(0)
  • 2020-11-30 02:16

    Got the same issue in my webpack/react project - it seems that there was an issue with the .babelrc file.

    I updated it as seen below and it did the trick:

    {
        "presets": [
            "@babel/preset-env",
            "@babel/preset-react"
        ],
        "plugins": [
            "transform-class-properties",
            "transform-object-rest-spread"
        ]
    }
    
    0 讨论(0)
提交回复
热议问题