Browser-sync: SyntaxError in micromatch when starting browser-sync

Created on 23 Apr 2019  路  11Comments  路  Source: BrowserSync/browser-sync

Issue details

A SyntaxError is thrown when starting browser-sync:

[13:07:39] Finished 'build' after 20 s
[13:07:39] Starting 'server'...
[13:07:39] 'server' errored after 7.79 ms
[13:07:39] /xxx/xxx/node_modules/micromatch/index.js:44
    let isMatch = picomatch(String(patterns[i]), { ...options, onResult }, true);
                                                   ^^^

SyntaxError: Unexpected token ...
    at createScript (vm.js:56:10)
    at Object.runInThisContext (vm.js:97:10)
    at Module._compile (module.js:542:28)
    at Module._extensions..js (module.js:579:10)
    at Object.require.extensions.(anonymous function) [as .js] (/xxx/xxx/node_modules/babel-register/lib/node.js:152:7)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)
    at Module.require (module.js:497:17)
    at require (internal/module.js:20:19)

Steps to reproduce/test case

  1. Run npm install with browser-sync@^2.10.0 as dev dependency
  2. Run gulp

Please specify which version of Browsersync, node and npm you're running

  • Browsersync [2.26.3]
  • Node [6.12.2]
  • Npm [3.10.10]

Affected platforms

  • [x] linux
  • [ ] windows
  • [ ] OS X
  • [ ] freebsd
  • [ ] solaris
  • [ ] other _(please specify which)_

Browsersync use-case

  • [ ] API
  • [x] Gulp
  • [ ] Grunt
  • [ ] CLI

for all other use-cases, (gulp, grunt etc), please show us exactly how you're using Browsersync

gulp.task('default',
    gulp.series(
        'build',
        server,
        watch
    )
);
function server(done) {
  'use strict';
  browser.init({
    server: PATHS.dist.base, port: PORT, open: false
  });
  done();
}

PATHS.dist.base: 'dist'
PORT: 1234

Most helpful comment

Introduced here (v2.26.4) as far as I can tell: in my own project, pinning browser-sync to "2.26.3" in my own package.json prevented the issue from occuring.

This is the commit in browser-sync which introduces this issue:

https://github.com/BrowserSync/browser-sync/commit/05a58dbc3e788b7b9c84b9c0f4ab84f60bc619b1

Specifically, in the package.json file:
packages/browser-sync/package.json

"micromatch": "2.3.11",
... is replaced with:
"micromatch": "^4.0.2",

Please see:
https://github.com/micromatch/micromatch/issues/159

My suggestion is to revert to the latest 3.x version of micromatch ("3.1.10"), which does not make use of the "..." three-dots spread syntax https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Spread_syntax in index.js

Compare:
https://github.com/micromatch/micromatch/blob/master/index.js
https://github.com/micromatch/micromatch/blob/3.1.10/index.js

All 11 comments

+1

I have the same issue.

Browsersync [2.26.4]

Introduced here (v2.26.4) as far as I can tell: in my own project, pinning browser-sync to "2.26.3" in my own package.json prevented the issue from occuring.

This is the commit in browser-sync which introduces this issue:

https://github.com/BrowserSync/browser-sync/commit/05a58dbc3e788b7b9c84b9c0f4ab84f60bc619b1

Specifically, in the package.json file:
packages/browser-sync/package.json

"micromatch": "2.3.11",
... is replaced with:
"micromatch": "^4.0.2",

Please see:
https://github.com/micromatch/micromatch/issues/159

My suggestion is to revert to the latest 3.x version of micromatch ("3.1.10"), which does not make use of the "..." three-dots spread syntax https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Spread_syntax in index.js

Compare:
https://github.com/micromatch/micromatch/blob/master/index.js
https://github.com/micromatch/micromatch/blob/3.1.10/index.js

This is happening because the engine property specified in the browser-sync package.json is 0.8.0.

If we want to keep compatibility with older vesions of Node I suppose we could add a pre-publish step to transpile. But we鈥檇 have to do it in all dependencies of micromatch as well. Id be willing to discuss further if someone wants to create an issue at micromatch with ideas for a solution that will make everyone happy.

Did I get it right that this is a node 6 problem? So the solution would be to stay on 6 and use previous versions or update to at least node 8?

+1

I have the same issue.

Browsersync [2.26.4]

Encountered this today and lost several hours of work diagnosing the problem.

Based on @michaellenahan 's comment I changed the version of micromatch to "3.1.10" in browser-sync's package.json ... That got me running again, but I have no idea what other problems that may introduce, if any.

I'm also facing the same issue. Changed the micromatch version to 3.1.10 in browser-sync package.json.
It is fine until local environment.
Even I tried with browser-sync new version in main package.json. But no luck.

I'm also facing the same issue. (version v2.26.9)
Pinned browser-sync version to 2.26.7 solved the problem.

@jcyuyi can you try [email protected] on node version 8+

if you're using anything below node 8, just stay pinned on 2.26.7 :)

@jcyuyi can you try [email protected] on node version 8+

if you're using anything below node 8, just stay pinned on 2.26.7 :)

I tried [email protected] on node version 8.17.0 and it wasn't working for me. So I pinned it to 2.26.7 and that did the trick.

Was this page helpful?
0 / 5 - 0 ratings