Cannot find module '@babel/core'

后端 未结 12 612
再見小時候
再見小時候 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: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.

提交回复
热议问题