electron-userland / electron-compile

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

exports is not defined #267

Open cezarsmpio opened 6 years ago

cezarsmpio commented 6 years ago

I've created a single file called configs.ts and my main.ts are importing some third-party libraries and this file. My console is showing to me the following error:

Uncaught ReferenceError: exports is not defined
    at main.ts:2
(anonymous) @ main.ts:2

On my HTML, I'm calling the file directly:

<script src="js/main.ts"></script>

My configs.ts:

interface BooOptions {
  resize: {
    min: number;
    max: number;
  }
}

const defaultConfigs = <BooOptions>{
  resize: {
    min: 200,
    max: 200
  }
};

export default defaultConfigs;

and my libs:

import showdown from 'showdown';
import Mousetrap from 'mousetrap';
import debounce from 'lodash/debounce';

// Project dependencies
import defaultConfigs from './configs';

require('mousetrap-global-bind');

const $ = el => document.querySelector(el);

const app = $('#app');
const markdownSource = $('#js-markdown-source');
const markdownResult = $('#js-markdown-result');
const markdownResizer = $('#js-resizer');
const markdown = new showdown.Converter();

Am I doing something wrong?

Thanks!

burtonator commented 6 years ago

same issue.. I'm not sure what's going on but this is the main issue I keep running into.

sebasgarcep commented 6 years ago

Right now this issue is forcing me to integrate Typescript with Electron by hand. Has anyone solved this yet? Or are there any other active projects that integrate Typescript into Electron?

burtonator commented 6 years ago

Check out my config here:

https://github.com/burtonator/polar-bookshelf

What I'm doing is loading the main app via require() and then I load the .js files from the filesystem. They HAVE to be loaded via require though or it won't work.

It's really confusing to setup and honestly I kind of just got lucky. This way you don't need to use webpack or babel or anything. I'm just using the standard typescript setup.

cloverich commented 5 years ago

When you include your main file like this:

<script src="./main.js">

instead of:

    <script>
        // https://github.com/electron/electron/issues/2863
        require('./index.js');
    </script>

The script will run in a browser context, and node variables like exports will not be available. You will run into a similar situation if you disable nodeIntegration when you create the window. Your options are: