sweetalert2_1.default is not a function
See original GitHub issueI’m trying to switch from sweetalert to sweetalert2.
Is anyone using this successfully with webpack2 and angular2?
Whatever i try, i always get this error:
Error in :0:0 caused by: sweetalert2_1.default is not a function
My component is the most simple i can guess
import swal from "sweetalert2";
import {Component, OnInit} from "@angular/core";
@Component({
selector: "dashboard",
template: require("./dashboard.template.html")
})
export class Dashboard implements OnInit {
ngOnInit() {
swal("Hi from webpack!");
}
}
The code generated by webpack looks like this:
var sweetalert2_1 = __webpack_require__(1334);
var core_1 = __webpack_require__(0);
var Dashboard = (function () {
function Dashboard() {
}
Dashboard.prototype.ngOnInit = function () {
sweetalert2_1.default("Hi from webpack!");
};
Dashboard = __decorate([
core_1.Component({
selector: "dashboard",
template: __webpack_require__(1387)
}),
__metadata('design:paramtypes', [])
], Dashboard);
return Dashboard;
}());
exports.Dashboard = Dashboard;
EDIT: When replacing the import with require the bundle is fine and it works
So replace
import swal from "sweetalert2";
with
var swal = require("sweetalert2");
But then, no TypeScript Type definitions are recognized 😕
Does anyone know how to workaround?
Issue Analytics
- State:
- Created 7 years ago
- Comments:10 (5 by maintainers)
Top Results From Across the Web
sweetalert2_react_content_1.default is not a function - ...
I have a react module where i am using TypeScript. I want to use html within a Swal-component, and that just doesn't work....
Read more >SweetAlert2 - a beautiful, responsive, customizable and ...
A beautiful, responsive, customizable and accessible (WAI-ARIA) replacement for JavaScript's popup boxes.
Read more >typeerror: (0 , express_1.default) is not a function
I'm getting [TypeError: (0 , express_1.default) is not a function for my code. import express from "express"; const app = express (); //...
Read more >(0 , import_defineToJSON.default) is not a function - Bugs
When trying to import '@8base/auth' to a Vite+Vue 3 project, the following error is trigger by the import statement. Uncaught TypeError: (0 ......
Read more >Calling Apex function results in a "default(...).this is not ...
I found an answer, but wanted to leave this up in case it frustrates anyone else. I updated my VS Code LWC Extension...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@readme42 I presume you’re using TypeScript 1.x? Please try my test branch to fix this by running
npm i -S toverux/sweetalert2#fix/named-exports
, and use the import syntaximport swal from "sweetalert2";
. That should work.@limonte I think that’s because older versions of TypeScript don’t like implicit default exports. By changing the way we export the lib using named exports, that should work everywhere, and fix usage in TypeScript 1.x. TypeScript 2.x support implicit default exports for interoperability if I remember correctly. Before upgrading to TS 2 in one of my apps, I also had to use
import swal = require('sweetalert2');
, otherwise it would have resulted in the same error.See https://github.com/toverux/sweetalert2/commit/13867fd217d4dfd71ab90497af72bf7f9a64d090
Thanks, good job.