Skip to content

Undefined "exports" when nothing is exported  #30718

Closed
@cawoodm

Description

@cawoodm

I'm going to be brave and revive the perennial and duplicated ReferenceError: exports is not defined issue. I have read the duplicate issues and seen no solution.

TLDR: TypeScript compiles .js files which contain an extraneous reference to exports which breaks apps.

Example:

app.ts

import {sayHello} from "./func";
sayHello("you")

func.ts

export function sayHello(name){console.log("Hello " + name)}

app.js

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tmp_1 = require("./func");
tmp_1.sayHello("you");

Line 2 of app.js is rejected by platforms like electron which don't know "exports".

I think the impasse is:

  1. The electron guys say: Typescript should use modules.exports which we do support.
  2. The typescript guys say: Electron should support exports

Workaround: Manually change the references (be the post-compiler) from Object.defineProperty(exports, "__esModule", { value: true }); to Object.defineProperty(module.exports, "__esModule", { value: true });

Would be nice if tsc would play nice with electron: as things stand I see no way of using tsc with electron without manually post-compiling the JS.

Electron v4.0.6 (Windows) with node v10.11.0
TSC Version 3.4.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    QuestionAn issue which isn't directly actionable in code

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions