Closed sosoba closed 3 years ago
It's because tslib.js is not an ES module.
See: https://github.com/microsoft/tslib/blob/master/tslib.js#L257 If you search the file, you'll find no import nor export statements, as you already discovered.
You'll need to import tslib.es6.js instead. It's a hassle, I know. If you use the new browser import map you could add something like "tslib": "/node_modules/tslib/tslib.es6.js"
to the import map JSON.
I am watching this issue because I think TypeScript should switch to tslib.es6.js
when using "ESNext"
in tsconfig.json
. It's a bug IMHO.
May be you can publish in parallel package? See (https://gitlab.com/sosoba/tslib)
npm install tslib@npm:@sosoba/tslib
I solved the problem with the help of an import map. My project already uses an import map, so it was easy to have or to modify the property "tslib": "/node_modules/tslib/tslib.es6.js"
in the "imports"
object of the import map. It's still a hassle because when tslib fixes this bug I will need to remove this work-around.
It looks like https://github.com/microsoft/tslib/pull/44 is the solution to this (rename tslib.es6.js
-> tslib.mjs
)
I am not sure about the .mjs
extension. I don't know, perhaps it's better the TypeScript compiler emit the right import or require instead.
Possibly related to this: https://github.com/typegoose/typegoose/issues/172
The offer #84 will solve the problem
When Typescript compiler produces esm output, ex:
source test.ts
dest test.js
Node 12/13 (which support esm natively) give error:
I seems to me, that Node treat
tslint
like ascjs
module but histslib.js
does not contain standardcjs
export.default
expression.