Skip to content

Undefined "exports" when nothing is exported #15795

Closed
@Johnz86

Description

@Johnz86

TypeScript Version: typescript@2.3.2

Code

import { render } from "react-dom";
import * as React from "react";
import { initLocales } from "./gui/components/intl";

document.addEventListener("DOMContentLoaded", (event) => {
    initLocales(true);

    const [viewComponentName] = new URL(window.location.href).search.substr(1).split("&");
    const view = require(`./gui/views/${viewComponentName}`).default;
    render(React.createElement(view, null), document.getElementById("appcontainer"));

});

Expected behavior:

"use strict";
const react_dom_1 = require("react-dom");
const React = require("react");
const intl_1 = require("./gui/components/intl");
document.addEventListener("DOMContentLoaded", (event) => {
    intl_1.initLocales(true);
    const [viewComponentName] = new URL(window.location.href).search.substr(1).split("&");
    const view = require(`./gui/views/${viewComponentName}`).default;
    react_dom_1.render(React.createElement(view, null), document.getElementById("appcontainer"));
});

Actual behavior:

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const react_dom_1 = require("react-dom");
const React = require("react");
const intl_1 = require("./gui/components/intl");
document.addEventListener("DOMContentLoaded", (event) => {
    intl_1.initLocales(true);
    const [viewComponentName] = new URL(window.location.href).search.substr(1).split("&");
    const view = require(`./gui/views/${viewComponentName}`).default;
    react_dom_1.render(React.createElement(view, null), document.getElementById("appcontainer"));
});

This is a recurrnig issue. #14351
I reported this previously.
After compilation appears

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

and the result is "Uncaught ReferenceError: exports is not defined.

Ther is no actual module exported in the file. If I manually remove this piece of code everything works fine.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Needs More InfoThe issue still hasn't been fully clarified

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions