Webpack + Babel: Couldn't find preset “es2015” relative to directory

前端 未结 5 1550
情歌与酒
情歌与酒 2020-12-13 20:35

I have a React project using Webpack and Babel. When I created it on an office computer, the Webpack ran fine. When I cloned the project onto my personal computer, it gave t

相关标签:
5条回答
  • 2020-12-13 20:48
    npm install babel-preset-es2015 babel-preset-stage-2 --save
    

    It's worked for me.

    0 讨论(0)
  • 2020-12-13 20:49

    For me, I had to install the package globally.

    npm install babel-preset-es2015 --save -g

    0 讨论(0)
  • 2020-12-13 20:54

    npm i or npm install

    should install all the packages in your package.json dependencies and dev dependencies (so long as your NODE_ENV environment variable does not equal production).


    To check if you have a particular package installed you may do:

    npm ls babel-preset-es2015

    If for some reason your NODE_ENV is production and you would like to install dev dependencies you can use:

    npm install --only=dev

    Conversely, the following may be used on production machines that are dealing with already built code and do not need access to any development dependencies:

    npm install --only=prod


    I'd recommend creating a .babelrc in the root of your repo with the following content:

    { "presets": [ "es2015", "react" ] }


    For the webpack config you may want to specify some other options:

    { context: __dirname
    , resolve: { root: __dirname, extensions: [ '.js', '.jsx', '.json' ] }
    }
    

    in addition to the rest of your configuration, this tells webpack where the root directory of the bundling should take place from and what file extensions to treat as modules (which extensions you can omit in require / import statements).

    I'd recommend checking out webpack's resolve.extensions for more information on that bit.

    0 讨论(0)
  • 2020-12-13 20:59
    npm install babel-preset-es2015
    

    does that help?

    0 讨论(0)
  • 2020-12-13 21:07

    I resolved this issue when I removed .babelrc (hidden) file from "/Users/username" directory.

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