Gulp -Sourcemaps, SyntaxError: Unexpected Token>

Gulp / npm noobie here.

I am trying to use gulp -sourcemaps and for some reason it crashes on var sourcemaps = require('sourcemaps'). (It only breaks when this line in the file)

gulpfile:

var gulp = require('gulp');
var uglify = require('gulp-uglify');
var concat = require('gulp-concat');
var sourcemaps = require('gulp-sourcemaps');


gulp.task('generateApp', function () {
    return gulp.src([some paths...])
        .pipe(sourcemaps.init())
        .pipe(concat('app.min.js'))
        .pipe(uglify())
        .pipe(sourcemaps.write())
        .pipe(gulp.dest(path...));
});

Error:

C:\Projets\node_modules\strip-bom\index.js:2
module.exports = x => {
                    ^
SyntaxError: Unexpected token >
at Module._compile (module.js:439:25)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at Object.<anonymous> (C:\Projets\node_modules\gulp-sourcemaps\src\init.js:10:14)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)

Does anyone encounter this type of error? I tried to do this without any success.

+4
source share
1 answer

I just started getting the same error and fixed it by replacing the code in C:\Projects\node_modules\strip-bom\index.jswith this:

'use strict';
module.exports = function (x) {
    if (typeof x !== 'string') {
        throw new TypeError('Expected a string, got ' + typeof x);
    }

    // Catches EFBBBF (UTF-8 BOM) because the buffer-to-string
    // conversion translates it to FEFF (UTF-16 BOM)
    if (x.charCodeAt(0) === 0xFEFF) {
        return x.slice(1);
    }

    return x;
};

Then I had to run npm rebuild node-sassit to work again. This seems to be a problem with an older version of the Strip-bom node module .

: https://github.com/sindresorhus/strip-bom/commit/e2a3c3b83706ee5baac284f3862d3f6b9e1564e5

:

Node. Strip-bom ES2015 (ES6), node 5.0+. ( node ES2015 )

Node, :

node -v

5.0, . node :

https://nodejs.org/en/

Node npm rebuild node-sass, Gulp.

- , node, , Louis, node .

+12

Source: https://habr.com/ru/post/1658699/


All Articles