Cannot find module '@babel/core'

后端 未结 12 573
再見小時候
再見小時候 2021-01-30 16:01

I am following along with this webpack4/react tutorial:

https://www.youtube.com/watch?v=deyxI-6C2u4

I have followed it exactly up until the part where he runs np

相关标签:
12条回答
  • 2021-01-30 16:26

    I solved the same error by removing all the babel modules from dev Dependencies executing the below command:

    npm install -D babel-loader @babel/core @babel/preset-env

    You can refer to this link if the above command does not work:

    [https://github.com/babel/babel/issues/8599#issuecomment-417866691]

    0 讨论(0)
  • 2021-01-30 16:27

    The recent Babel upgrade to version 7 changed the namings of the node packages.

    For instance, now you have to install

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

    and

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

    to get it working with React. Then you can use these in your .babelrc file:

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

    Or as alternative, when not having a .babelrc, in your package.json:

    ...
    "keywords": [],
    "author": "",
    "license": "ISC",
    "babel": {
      "presets": [
        "@babel/preset-env",
        "@babel/preset-react"
      ]
    },
    "devDependencies": {
    ...
    

    If you want to get more into it, you can checkout this recent Webpack + Babel + React setup.

    0 讨论(0)
  • 2021-01-30 16:31

    Try running this.

    npm install @babel/core --save
    

    babel changed their package so your babel-core will not be the same as @babel/core.

    0 讨论(0)
  • 2021-01-30 16:33

    for those of you who use @babel/core alongside babel-node: i just installed @babel/core using npm i @babel/core --save-dev but when i tried to use babel-node it does not recognized the @babel/core package, i uninstalled @babel/core and installed it again using npm i @babel/core --save and it worked again!

    0 讨论(0)
  • 2021-01-30 16:36

    I removed the existing npm uninstall babel-core babel-preset-env babel-preset-react

    and added their new names npm install --save-dev @babel/core @babel/preset-env @babel/preset-react that's works for me as perfectly fine.

    0 讨论(0)
  • 2021-01-30 16:38

    I fixed with:

     npm install --save-dev babel-loader@7 babel-core babel-preset-env webpack webpack-cli -D
    
    0 讨论(0)
提交回复
热议问题