search

Home  >  Q&A  >  body text

javascript - gulp cannot use babel properly

Already installed babel and presets-es2015

There are corresponding dependencies in package.json

{
  "name": "test",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "babel-preset-es2015": "^6.24.1",
    "gulp": "^3.9.1",
    "gulp-babel": "^6.1.2"
  }
}

gulpfile.js

var gulp = require("gulp");
var babel = require("gulp-babel");

gulp.task("es5", function() {
    return gulp.src("es5/test.js")
        .pipe(babel({
            presets: ["es2015"]               
        }))
        .pipe(gulp.dest("es6"));
});

Directory Structure:

An error is reported when running: Error: Couldn't find preset "es2015" relative to directory "C:\Users\Li\Desktop"

Use: presets: ['es2015'].map(require.resolve) to report: Error: Cannot find module 'es2015'

But I have installed them all, and they are also displayed in package.json

PHP中文网PHP中文网2814 days ago814

reply all(2)I'll reply

  • PHPz

    PHPz2017-05-16 13:44:17

    1. babel-presets-es2015First check whether it is installed properly.

    2. The content in the second pipe is the same as .babelrc, only one is needed

    reply
    0
  • 滿天的星座

    滿天的星座2017-05-16 13:44:17

    Try it

    npm i babel-core -D

    reply
    0
  • Cancelreply