pikachu
pikachu

Reputation: 31

electron + typescript compilation

When I try to compile a sample TypeScript Electron project, I get the error 'chrome' does not exist on type ProcessVersions. The Electron site claimed that just adding the node_module Electron would enable TypeScript typings, but I can't make it work.

Upvotes: 0

Views: 517

Answers (1)

Fenton
Fenton

Reputation: 250802

I have created a cut down version for you to follow along with. You haven't posted quite enough about your application for the answer to be more specific than this...

Electron should be a development dependency, so here it is in the package file for the project:

package.json

{
    "name": "example",
    "private": true,
    "devDependencies": {
        "electron": "^1.7.9"
    }
}

Electron is imported on the first line of this application (simplified, but working autocompletion and no compiler errors).

import { app, BrowserWindow } from "electron";
import * as path from "path";
import * as url from "url";

const chr = process.versions.chrome;

The type information for process.versions.chrome is found in node_modules\electron\electron.d.ts.

  interface ProcessVersions {
    electron: string;
    chrome: string;
  }

Upvotes: 1

Related Questions