What’s the purpose of `Object.defineProperty(exports, “__esModule”, { value: !0 })`?

It helps to correctly import a default export in CommonJS/AMD/UMD module format.

A default import (i.e. import d from “foo”) for a CommonJS/AMD/UMD module is equivalent to

const d = require("foo").default

But most of the CommonJS/AMD/UMD modules available today do not have a default export, making this import pattern practically unusable to import non-ES modules
(i.e. CommonJS/AMD/UMD).
For instance

import fs from "fs" 

or

import express from "express" 

are not allowed.

To allow default imports in CommonJS/AMD/UMD (e.g. import fs from “fs”), the typescript compiler adds __esModule flag and checks it in a transpiled code (from ES6 to CommonJS). It imports default exports by using an __importDefault helper function (which checks the __esModule flag).

var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
}
exports.__esModule = true;
var bar_1 = __importDefault(require("bar"));

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)