question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Null coalescing operator and optional chaining not handled in main build

See original GitHub issue

Describe the bug Hi,

Thanks for this plugin. “New” syntax like “Null coalescing operator” and “optional chaining” make the main build fail.

error  in ./src/electron/main.ts

Module parse failed: Unexpected token (14:25)
File was processed with these loaders:
 * ./node_modules/ts-loader/index.js
You may need an additional loader to handle the result of these loaders.
|         { scheme: 'app', privileges: { secure: true, standard: true } },
|     ]);
>     console.log('false' ?? 'true');
|     await registerAppEventsListeners(app);
|     createMenu();

 @ multi ./src/electron/main.ts
 error  in ./src/electron/main.ts

Module parse failed: Unexpected token (15:20)
File was processed with these loaders:
 * ./node_modules/ts-loader/index.js
You may need an additional loader to handle the result of these loaders.
|     ]);
|     const foo = {};
>     console.log(foo?.bar || 'fff');
|     await registerAppEventsListeners(app);
|     createMenu();

 @ multi ./src/electron/main.ts

To Reproduce Steps to reproduce the behavior: Add any of them in your main file.

console.log('foo' ?? 'bar');
console.log(foo?.bar);

Expected behavior Build ok with transpilation needed for the electron version (so none I think).

Environment (please complete the following information):

  • custom config for vcp-electron-builder:
   mainProcessFile: path.join(__dirname, 'main.ts'),
   mainProcessTypeChecking: true,
   mainProcessWatch: [__dirname],
  • terminal output from running vue info:
System:
    OS: macOS 11.1
    CPU: (8) x64 Apple M1
  Binaries:
    Node: 14.15.4 - /usr/local/bin/node
    Yarn: 1.22.10 - /opt/homebrew/bin/yarn
    npm: 6.14.10 - /usr/local/bin/npm

vcp-electron-builder version : 2.0.0-rc.6

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
nklaymancommented, Feb 23, 2021

The VueJS standard build config is very different as it is designed to target the browser, rather than the Electron main process. There are a lot of config differences between the two targets, so the main process uses a custom configuration.

0reactions
mathieutucommented, Mar 9, 2021

@nklayman actually the yarn resolutions did not fix the issue.

As you can see I have the correct versions.

λ › yarn why terser-webpack-plugin
...                                                                                                                             
=> Found "vue-cli-plugin-electron-builder#terser-webpack-plugin@4.2.3"
info This module exists because "vue-cli-plugin-electron-builder" depends on it.

...


λ › yarn why terser                                                                                                                                            ...
=> Found "vue-cli-plugin-electron-builder#terser@5.6.0"
info Reasons this module exists
   - "vue-cli-plugin-electron-builder#terser-webpack-plugin" depends on it
   - Hoisted from "vue-cli-plugin-electron-builder#terser-webpack-plugin#terser"
...

But actually here, the ts-loader should be able to handle it natively, shouldn’t be? 🤔


EDIT:

I’ve seen https://github.com/TypeStrong/ts-loader/issues/1061#issuecomment-591571634.

I don’t understand everything, but I’ve set the target to es2019 instead of vue-cli recommended esnext target, and it works…!

So nothing to do with parser, but a breaking change in typescript with es2020… 🤷

Read more comments on GitHub >

github_iconTop Results From Across the Web

Nullish coalescing operator (??) - JavaScript - MDN Web Docs
The nullish coalescing operator treats undefined and null as specific values. So does the optional chaining operator ( ?. ), which is useful...
Read more >
Is there a "null coalescing" operator in JavaScript?
this solution works like the SQL coalesce function, it accepts any number of arguments, and returns null if none of them have a...
Read more >
Optional chaining and nullish coalescing in TypeScript
In TypeScript, optional chaining is defined as the ability to immediately stop running an expression if a part of it evaluates to either...
Read more >
What is wrong with optional chaining and how to fix it - DEV ...
Unfortunately both versions have the same issue, for z being empty string, it does not call func function. Another issue is that in...
Read more >
How to Use Optional Chaining and Nullish Coalescing in ...
The nullish coalescing operator may be used after optional chaining in order to build a default value when no value is found.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found