dcranmer's avatar

syntax error with nullish coalescing operator

I'm using Laravel Mix 6.0.32. I'm getting the following error when I run npm run dev:

[webpack-cli] /Users/pweil/code/wisconsin-idea/webpack.mix.js:25
    this.watch = config.watch ?? ['routes/**/*.php'];
                               ^

SyntaxError: Unexpected token '?
    at new Script (vm.js:88:7)
    at NativeCompileCache._moduleCompile (/Users/pweil/code/wisconsin-idea/node_modules/v8-compile-cache/v8-compile-cache.js:240:18)
    at Module._compile (/Users/pweil/code/wisconsin-idea/node_modules/v8-compile-cache/v8-compile-cache.js:184:36)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
    at Module.load (internal/modules/cjs/loader.js:863:32)
    at Function.Module._load (internal/modules/cjs/loader.js:708:14)
    at Module.require (internal/modules/cjs/loader.js:887:19)
    at require (/Users/pweil/code/wisconsin-idea/node_modules/v8-compile-cache/v8-compile-cache.js:159:20)
    at module.exports (/Users/pweil/code/wisconsin-idea/node_modules/laravel-mix/setup/webpack.config.js:8:5)
    at loadConfigByPath (/Users/pweil/code/wisconsin-idea/node_modules/webpack-cli/lib/webpack-cli.js:1760:27)

In my mix file I have some code to watch route changes that uses the ?? operator:

mix.extend('ziggy', new class {
  register(config = {}) {
    this.watch = config.watch ?? ['routes/**/*.php'];
    this.path = config.path ?? '';
    this.enabled = config.enabled ?? !mix.inProduction();
[...]

What might be causing this error? Webpack 5 is supposed to support this syntax.

0 likes
2 replies
dcranmer's avatar

@Umid82 yeah sure, I can write it differently and it works fine as a workaround. So this isn't preventing me from doing what I need to do. But my question is why Webpack 5 is flagging this operator as an error. And if it is flagging this as an error, and if there is something wrong underneath (maybe Webpack is not the root cause?), might this cause other errors with more recent syntaxes?

Please or to participate in this conversation.