I have a commonjs module, which was generated by Typescript 3.3.3.
Is it possible to use it with an es6 import statement? Here's what I have tried.
The generated module exports CountUp like this at the end of the file:
exports.CountUp = CountUp; In my main.js:
import { CountUp } from './js/countUp.js'; And in index.html:
<script src="./js/countUp.js"></script> <script src="./main.js" type="module"></script> But I get
countUp.js:13 Uncaught ReferenceError: exports is not defined at countUp.js:13
(Note: countUp.js is now distributed as an es6 module)
export class CountUp {}orexport function CoutUp(){}What does youtsconfig.jsonlook like?countUpcode seems not to check whetherexportsexists before attempting the CommonJS export.Object.definePropert(exports, ...)— ifexportsis not defined, that's an exception.