Gulp-Sourcemaps,SyntaxError:Unexpected token> [英] Gulp-Sourcemaps, SyntaxError: Unexpected token >

查看:375
本文介绍了Gulp-Sourcemaps,SyntaxError:Unexpected token>的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我尝试使用gulp-sourcemaps,出于某种原因,它崩溃在 var sourcemaps = require('sourcemaps')。(只有当这行在文件中时才会崩溃)

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 ...));
});

错误:

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

有没有人遇到这种类型的错误?
我尝试了谷歌它,没有任何成功。

解决方案

我刚开始得到相同的错误,并修复它替换 C:\Projects\\\
ode_modules\strip-bom\index.js
中的代码:

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

//捕获EFBBBF(UTF-8 BOM),因为缓冲区到字符串
//转换将其转换为FEFF(UTF-16 BOM)$ b $如果(x.charCodeAt(0)=== 0xFEFF){
return x.slice(1);
}

return x;
};

然后,我必须运行 npm rebuild node-sass 让它再次运作。这似乎是旧版 Strip-bom 节点模块的问题。



欲了解更多信息,请查看: https://github.com/sindresorhus/strip-bom/commit/e2a3c3b83706ee5baac284f3862d3f6b9e1564e5



UPDATED ANSWER:



此错误是由于使用旧版本的节点而引起的。 Strip-bom模块现在使用需要Node 5.0+的 ES2015(ES6)语法。 (请参阅Node的ES2015支持列表此处

<要测试您的Node版本,请运行:

node -v



如果它小于5.0,则需要更新它。您可以在此下载最新版本的Node:



https: //nodejs.org/en/

在安装新版本的Node之后,我仍然需要运行 npm rebuild node- sass 让Gulp重新开始运行。

如果您不想更新您的Node版本,前面的答案仍然有效,但是,指出,手动编辑节点模块文件不是最佳做法。


Gulp / npm noobie here.

I'm trying to use gulp-sourcemaps, and for some reason, it crashes on var sourcemaps = require('sourcemaps').(It crash only when this line's 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)

Has anyone encounter this type of error? I tried to google it, without any success.

解决方案

I just started getting the same error and fixed it by replacing the code in C:\Projects\node_modules\strip-bom\index.js with 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-sass to get it to work again. It seems to be an issue with an older version of the Strip-bom node module.

For more info, check this out: https://github.com/sindresorhus/strip-bom/commit/e2a3c3b83706ee5baac284f3862d3f6b9e1564e5

UPDATED ANSWER:

This error is caused by using an older version of Node. The Strip-bom module is now using ES2015 (ES6) syntax which requires Node 5.0+. (See Node's ES2015 support list here)

To test your version of Node, run:

node -v

If it's less than 5.0, you'll need to update it. You can download the newest version of Node here:

https://nodejs.org/en/

After installing the new version of Node, I still needed to run npm rebuild node-sass to get Gulp up and running again.

The former answer will still work if you don't want to update your Node version, however, as Louis pointed out, manually editing node module files is not a best-practice.

这篇关于Gulp-Sourcemaps,SyntaxError:Unexpected token&gt;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆