Babel/webpack exports a TypeScript/ES6 module as _esModule with a default property

After converting my JavaScript application to TypeScript and using ES6-style exports, I encountered an issue with babel/webpack not exporting the code correctly.

The use of export default... syntax by TypeScript results in babel transforming it into an esModule object where the class is nested under a default property.

This new object format poses problems for users trying to make use of the code.

I attempted to resolve this by adding the babel-plugin-add-module-exports plugin, but unfortunately, it did not address the issue. Could TypeScript integration be causing complications?

.babelrc:

{
    "plugins": [
        "add-module-exports",
        "lodash"
    ]
}

tsconfig.json:

{
  "compilerOptions": {
    "target": "es2015",
    "module": "commonjs"
  }
}

webpack.config.js:

entry: {
    'myfile.ts'
},
output: {
    filename: 'myfile.js',
    library: 'MyApp',
    libraryTarget: 'umd'
},
resolve: {
    extensions: ['', '.ts', '.js']
},
module: {
    loaders: [{
        test: /\.ts$/, loader: 'babel!ts-loader'
    }]
}

myfile.ts simply exports a class:

export default class MyApp {...

Answer №1

To change the bundle output into a global variable, you can set the libraryTarget property to UMD format, which is compatible with both Commonjs and AMD

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Live tweet moderation made easy with the Twitter widget

Currently in search of a widget, jQuery plugin, hosted service, or equivalent that can be easily integrated into an HTML page. This tool should display and automatically update live tweets featuring a specific hashtag, only from designated accounts set by ...

Employ a PHP variable within Javascript/Ajax discreetly to prevent it from being revealed in the inspect element tool

I am looking to utilize the Mandrill API for sending emails. I have stored my API key in a PHP variable, but when I include it as apikey='<?php echo $apikey; ?>';, it becomes visible in the inspect element. Is there a way to hide, encrypt, ...

Clearing out content from owlCarousel: A step-by-step guide

I have a model where I am displaying a couple of images in an owlCarousel div. The issue arises when I close the model and open it again, the new set of images get appended to the previous ones. I want to clear all items from the previous model and reini ...

Difficulty with Angular's Interpolation and incorporating elements

I've encountered an issue with String Interpolation while following an Angular course. In my server.component.ts file, I've implemented the same code as shown by the teacher in the course: import { Component } from "@angular/core"; @Component ( ...

Apply a specific class to every element on a page after selecting a menu item

Upon clicking on a menu item with the class ".menu-item", I want all elements on the page with the class ".chrome" to have the class ".current" added and then immediately removed. <ul id="navigation"> <li class="menu-item"><a href="#lin ...

Running a Neo4j Cypher query with the help of jQuery

I've been attempting to create an Ajax call using jQuery to a Neo4j Server, both residing on the same machine. However, I keep encountering errors in the response. This is how my ajax call is written: var request = $.ajax({ type: "POST", url ...

Discord.js Time Limit Functionality

What is the proper way to implement the timeout functionality in discord.js ? I am specifically referring to the new timeout feature, and not just assigning a mutedrole ...

Combining Components in NextJs Without Using Functional Components

I created a module, then split it into components and now I'm trying to piece it back together. The individual components are functioning correctly. Some components are nested inside the div of another component. I attempted to group them within a d ...

`Turn nested JSON into a formatted list using jquery`

I am currently facing two challenges: I am having trouble with the HTML structure, as shown in the image below Current HTML structure: https://i.stack.imgur.com/GH46J.png Desired HTML structure: https://i.stack.imgur.com/Dq3Gn.png How can I create d ...

What is the best way to display JSON response as code instead of a string in AngularJS?

When retrieving my article from the database as a JSON object, I encounter an issue with the body content. The HTML codes in the body are displayed as strings within double quotation marks by AngularJS. How can I resolve this? Angular controller snippet: ...

displaying a message following the creation or transmission of an email via ajax

function handleRegistrationAjax(){ $this->load->library('form_validation'); $this->form_validation->set_rules('email','email','required|is_unique[register.email]'); if($this->f ...

How to change from using position: sticky to fixed after scrolling to a specific div

Is there a way to transition the position of sticky content from sticky to Fixed while scrolling down and moving to the next rows, keeping it fixed until just before the footer, where it should scroll again? For example, <!DOCTYPE html> <html ...

An elusive melody that plays only when I execute the play command

I am currently working on creating a music Discord bot using the yt-search library, however, I am encountering an issue where it returns undefined when trying to play a song and joins the voice channel without actually playing anything. My approach is to u ...

Menu manipulation: Shifting menus left and right with a click

Take a look at this link. There are 12 menu items, but only 4 are visible due to space constraint. The rest are hidden. Update: Jsfiddle cleaned up and removed my fiddle. I have provided an alternative link above. There was a missing jQuery part in my que ...

Changing the url in an $http.get request using AngularJS when a select event occurs

I am currently working with a customers.php file that produces JSON data. The list of JSON data changes when we modify a variable in the URL like so: customers.php?var=5 In my AngularJS project, I have created an HTML file with two distinct parts. The fi ...

Using Laravel to set cookies with Ajax

I am facing difficulties in setting cookies through laravel using ajax. Despite reading several questions and posts, I have not been able to find a solution. My issue involves a dropdown that triggers a javascript function to send its value to a controlle ...

Leverage the power of v-model props in your Vue 3 component to efficiently retrieve API breakpoints

I am currently working on integrating the API breakpoints in my child component. These components are designed for my football web application. The breakpoints are sourced from: api-football My challenge lies in passing multiple prop values into a c ...

What is the best way to link multiple return statements in Node.js using ioredis?

Currently utilizing ioredis and interested in retrieving the path and value shown in the code snippet below up to the anonymous function. console.log( function (jsonGraphArg) { return Redis.hget(jsonGraphArg[0], jsonGraphArg[1], function(error ...

Challenge with Merging Bootstrap Clean Blog Template with React Application

I am facing difficulties while trying to merge the Bootstrap Clean Blog Template (Link Attached) into my React App. This template is available for free. After downloading the template, I created a new react project and moved all static assets & files ...

The Date Picker pops up automatically upon opening the page but this feature is only available on IE10

There seems to be an issue with the date picker opening automatically on IE10, while it works fine in Firefox where it only appears when you click on the associated text box. Does anyone have insight into why this might be happening specifically in IE10? ...