Null coalescing operator and optional chaining not handled in main build
See original GitHub issueDescribe 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:
- Created 3 years ago
- Comments:5 (5 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
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.
@nklayman actually the yarn resolutions did not fix the issue.
As you can see I have the correct versions.
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… 🤷