electron-userland / electron-compile

DEPRECATED: Electron supporting package to compile JS and CSS in Electron applications
1.01k stars 99 forks source link

ES6 imports not resolving properly with typescript #311

Open sploders101 opened 5 years ago

sploders101 commented 5 years ago

Long version

When using typescript with electron-compile, the typescript compiler will resolve to commonjs, requiring commonjs variants of ES6-imported modules. Many times, this is acceptable, but for things like vue-router and sfc's, which have separate es6-style variants declared as "module" in their package.json, it is not, because the structure of the exported object is different depending on the javascript standard you use. There is an option in the tsconfig.json's compiler options ("module": "es2015",) that you can use to counter this, but then it exports as es6 javascript, which cannot be sent directly to node, but needs to be compiled again through babel or a similar precompiler. It is possible to write functional code the way it is, but it doesn't play nice with editors that support typescript, which kind of defeats the purpose. It would be nice if we could have a gulp-like configuration, where we can pipe code through multiple compilers before sending it to node, but that's probably overkill.

TLDR

Typescript currently resolves package names to their commonjs variants when using "module": "commonjs". In order to work properly with editors like vscode and atom, we need to use ES6 syntax, so it must be changed to "module": "es6" which outputs code that is not syntactically correct for node, and must be pre-compiled again with babel before being sent to node.

Any help would be appreciated