Importing Typescript modules in the renderer process


#1

I have an issue which is similar to the issue here How to use TypeScript modules in Electron? however that doesn’t work for me as I can’t set the “node-integration” to false because it isn’t part of the BrowserWindowConstructorOptions type.

My issue is that I have a Typescript module which exports some classes. At the main process side this is fine and I import them like this:

import dataset = require("./dataset");

At the renderer process I have tried multiple ways of importing the class definitions:

import dataset = require("./dataset");
import {Data, Dataset, Device, Channel} from "./dataset";

This results in the compiler accepting it, however at runtime i get an “Uncaught ReferenceError: exports is not defined” error. The generated code has this line which I understand messes up the renderer as its not running in a node environment but within the browser:

Object.defineProperty(exports, "__esModule", { value: true });

This is from https://github.com/electron/electron/issues/2863 .

What I figure out is that I have to somehow manage to import the classes in a different way.

Doing this const dataset = require("./dataset"); does not include in typescript. I can’t access the types.

I’m stuck and out of ideas to how to fix this :confused:

afaik so I’m stuck at how to properly import typescript modules in the renderer process.