Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
530 views
in Technique[技术] by (71.8m points)

javascript - Error: Couldn't find preset "es2015" relative to directory

I get the following error when I trying to use babel.

Error: Couldn't find preset "es2015" relative to directory

webpack.config.js

module.exports = {
    entry: './main.js',
    ourput: {
        path:'./',
        filename:'index.js'
    },
    devServer:{
        inline:true,
        port:3333
    },
    module:{
        loaders:[
            {
                test:/.js$/,
                exclude:/node_modules/,
                loader:'babel',
                query:{
                    presets:['es2015','react']
                }
            }
        ]
    }
}

package.json

{
  "name": "es6-react-setup",
  "version": "1.0.0",
  "main": "main.js",
  "dependencies": {
    "babel-core": "^6.11.4",
    "babel-preset-es2015": "^6.9.0",
    "babel-preset-react": "^6.11.1",
    "babel-loader": "^6.2.4",
    "react": "^15.2.1",
    "react-dom": "^15.2.1",
    "webpack": "^1.13.1"
  },
  "devDependencies": {},
  "scripts": {
    "start": "webpack-dev-server"
  },
  "author": "",
  "license": "ISC",
  "description": ""
}

Terminal output Terminal output

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You need to have babel configured to use those presets. You can add this to your package.json

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

You can alternatively have a .babelrc file.

https://babeljs.io/docs/usage/babelrc/


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...