tko
tko copied to clipboard
Unable to load from an ES module
I'm in the process of modernizing my application moving it from AMD to ES modules. With the classic KO that was not possible and someone suggested to move to TKO, so I installed 4.0.0-alpha9.0
.
I'm using the importmap
(https://wicg.github.io/import-maps/) that is implemented in Chrome to map from "knockout"
to the
"../node_modules/@tko/build.reference/dist/build.reference.es6.js"
library.
Loading TKO this way: import ko from "knockout";
now gives a runtime error:
Uncaught SyntaxError: The requested module 'knockout' does not provide an export named 'default'
Loading that way: import * as ko from "knockout";
gives a different runtime error:
build.reference.es6.js:10 Uncaught TypeError: Cannot set properties of
undefined (setting 'ko')
at build.reference.es6.js:10
at build.reference.es6.js:11
Tried also with the other library build.reference.js:
with identical results. BTW, is build.reference.es6.js
the library that supports ES modules?
The modules are compiled from Typescript, but don't think this is relevant here.
Thanks for your help. I'm quite desperate.
The real problem is that both typeof exports
and typeof module
are undefined, so I cannot import the library this way as expected: import tko from "..../build.reference.es6.js"
Any idea how to import tko in an ES Module? Thanks! mario