javascript - gulp cannot use babel properly
PHP中文网
PHP中文网 2017-05-16 13:42:17
0
2
761

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中文网

认证0级讲师

reply all(2)
PHPzhong
  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

滿天的星座

Try it

npm i babel-core -D

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!