Gulp-Sourcemaps, SyntaxError: Unexpected token >

独自空忆成欢 提交于 2019-12-05 14:50:32

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!