Requires Babel “7.0.0-0” but was loaded with “6.26.3”

前端 未结 10 847
深忆病人
深忆病人 2020-12-08 06:16

Keep getting this error no matter what I tried installing (babel wise) as I follow other similar reports. this is the stack trace:

error: bundli         


        
相关标签:
10条回答
  • 2020-12-08 06:56

    The issue on my side was a conflict between babel-core, imported by babel-register, and @babel/core, required by Babel documentation for latest usage and set as root npm dependency

    It seems babel-register has been moved to @babel/register. Babel didn't update docs with the new module name although they did for their cli/core packages

    Here is an update of setup babel doc that works for me:

    Installation

    npm install --save-dev @babel/register
    

    Usage

    In your package.json file make the following changes:

    {
      "scripts": {
        "test": "mocha --require @babel/register"
      }
    }
    
    0 讨论(0)
  • 2020-12-08 07:03

    Sometimes its because you have installed both babel-cli and babel/cli, or babel-core and @babel/core It causes conflicts

    So

    1) delete node_modules

    2) remove babel-cli, babel-core from your package.json, keep @babel/core, @babel/cli

    3) npm install

    babel-cli conflicts with @babel/cli

    bable-core conflicts with @babel/core

    0 讨论(0)
  • 2020-12-08 07:07

    It is NOT recommended to install babel globally. It might be that your IDE has recognized your globally installed package and is going based off of that one. Or what is more likely is that you have have packages that conflict with each other. e.g babel-cli conflicts with @babel/cli

    While you can install Babel CLI globally on your machine, it's much better to install it locally project by project.

    yarn remove global @babel/cli @babel/core
    

    In project directory...

    yarn remove babel-cli 
    yarn add @babel/cli @babel/core @babel/node --dev
    
    0 讨论(0)
  • 2020-12-08 07:08

    From the Babel Docs, I found that there is an issue with the order in which you install the deps.

    Note: Please install @babel/cli and @babel/core first before npx babel, otherwise npx will install out-of-dated babel 6.x.

    As per the usage docs. I found that removing both items from package.json and adding them in order, fixed my issue. Bizarre edge case.

    0 讨论(0)
  • 2020-12-08 07:11

    For the ones who still fighting that, 4 days ago Jest v24 released with native support for babel 7. enjoy.

    0 讨论(0)
  • 2020-12-08 07:16

    Looks like you need to install babel-core as the docs suggest: https://jestjs.io/docs/en/getting-started#using-babel

    yarn add --dev babel-jest babel-core@^7.0.0-bridge.0 @babel/core regenerator-runtime

    0 讨论(0)
提交回复
热议问题