electron-compile icon indicating copy to clipboard operation
electron-compile copied to clipboard

typescript example

Open farfromrefug opened this issue 8 years ago • 12 comments

Hi,

I am having a really hard time getting this to work with typescript. Could you create a boilerplate example? Maybe even with the main script being a typescript file.

Thanks

farfromrefug avatar Apr 29 '16 10:04 farfromrefug

What problems specifically are you running into?

mnquintana avatar Apr 30 '16 19:04 mnquintana

My typescript files don't seem to be compiled, even with electron-compilers. I get some cannot parse errors (sorry don't have the exact log right now). I think a boilerplate with typescript, even react typescript, would be great.

farfromrefug avatar May 01 '16 06:05 farfromrefug

I'm the same way.

I've installed Typings and electron/node as globalDependencies. My file looks like this:

{
  "name": "example-starter",
  "dependencies": {},
  "globalDependencies": {
    "electron": "registry:env/electron#0.37.6+20160723033700",
    "node": "registry:dt/node#6.0.0+20160807145350"
  }
}

The first two lines of my index.ts file look like:

import { app, autoUpdater, BrowserWindow } from 'electron';
import * as os from 'os';

...And I'm getting the following error:

App threw an error during load Error: L0: File 'electron.ts' is not a module. L1: File 'os.ts' is not a module.

What am I doing wrong? Do I need a .tsconfig.json file? If so, what should I put in it?

aendra-rininsland avatar Aug 10 '16 13:08 aendra-rininsland

@aendrew You need to install electron-prebuilt-compile as a dependency, and use that instead of the global electron binary. electron-prebuilt-compile wraps Electron with electron-compile, which is what lets you use TypeScript out of the box.

mnquintana avatar Sep 17 '16 00:09 mnquintana

And what do you import into your main.ts (Typescript) file? Neither electron-compile nor electron-prebuilt-compile come with typings and there are non available via npm install @types/...

Documentation on electron-compile is really bad.

MartinMajewski avatar Dec 15 '16 19:12 MartinMajewski

I agree, better documentation is needed. I am having the same issues with typescript. Imports are not working for me either, getting such_and_such.ts is not a module errors too.

vorktanamobay avatar Dec 18 '16 03:12 vorktanamobay

There still is no TypeScript example; am posting to prevent probot-stale from closing.

aendra-rininsland avatar Mar 20 '17 10:03 aendra-rininsland

am posting to prevent probot-stale from closing.

Sorry about that, @aendrew. It was an accident. Didn't mean to mark this issue as wontfix.

zeke avatar Mar 27 '17 23:03 zeke

@zeke It's cool! It's just probot doing it's probot-y thing. 😄

aendra-rininsland avatar Mar 28 '17 00:03 aendra-rininsland

Is there a typescript example yet?

My asar's main folder contains both generated *.js files and the original *.ts files that generated them. The *.ts files are causing javascript exceptions (on the import lines, but I suspect that's just because they are at the front of the files and I suspect any typescript syntax in the files would cause problems if I were to somehow fix the import issue).

I think I what I need to do is exclude the main *.ts files from being included in the asar but I can't figure out how to do that without also excluding the renderer *.ts files that the app I think needs to have included in the build process (I can't actually tell if the renderer *.ts files are required because I hit errors before I get there).

The app runs fine when running in development mode, its just when I try to build an actual executable that I hit these problems.

[edit: added] If I temporarily delete all the main *.ts files (keeping the renderer *.ts files intact) the app builds and runs correctly, so the issue is how to prevent the main *.ts files from getting copied into the asar without preventing the renderer *.ts files from going there or preventing the main *.ts files from getting loaded out of the asar by main without preventing the renderer *.ts files from getting loaded (and note that I don't currently share any *.ts files between main and renderer so for my case it's theoretically the simplest case, I think)

yoDon avatar Feb 01 '18 04:02 yoDon

I have a minimal working example over here: https://github.com/danzel/electron-compile-builder-typescript-example

Took me ages to figure out, please enjoy.

It doesn't use electron-prebuilt-compile, I couldn't get it to work when building, only in dev.

danzel avatar Aug 21 '18 20:08 danzel

Neither electron-compile nor electron-prebuilt-compile come with typings and there are non available via npm install @types/...

This pretty much sums up the entire problem for me right now. b/c the electron typings are not published to @types, they can't be installed independently of electron itself, which we have to replace with electron-compile, which for some reason decides not to pull the typing in from electron.

Now, this is fine from electron-compiles end, as it will compile fine, but it breaks external typescript, meaning that running tsc results in an error. This is important, as it means ides (such as WebStorm) that rely on the ts service also break.

This is why it's always better to publish typings to @types rather than inline them with your package. Can electron-compile please be updated to resolve this issue?

Either:

  • Allow us to install electron, or
  • Copy the type definitions from electron into electron-compile

G-Rath avatar Jan 08 '19 20:01 G-Rath