Problem with tslib and ES modules
See original GitHub issueWhen Typescript compiler produces esm output, ex:
{
"compilerOptions": {
"target" : "esnext",
"module": "esnext",
"experimentalDecorators": true,
"importHelpers": true,
}
}
source test.ts
@foo()
class Bar {
}
dest test.js
import { __decorate } from "tslib";
let Bar = class Bar {
};
Bar = __decorate([
foo()
], Bar);
Node 12/13 (which support esm natively) give error:
import { __decorate } from "tslib";
^^^^^^^^^^
SyntaxError: The requested module 'tslib' does not provide an export named '__decorate'
I seems to me, that Node treat tslint
like as cjs
module but his tslib.js
does not contain standard cjs
export.default
expression.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:4
- Comments:7 (1 by maintainers)
Top Results From Across the Web
TSConfig Option: esModuleInterop - TypeScript
This mis-match causes these two issues: the ES6 modules spec states that a namespace import ( import * as x ) can only...
Read more >Angular >=13 | jest-preset-angular - GitHub Pages
Using ES Modules. ES Modules support is new and may encounter issues. See example-app-v13 for an example with tests that ... tslib: 'tslib/tslib.es6.js',...
Read more >"This syntax requires an imported helper but module 'tslib ...
"tslib is not a dependency of angular itself. But rather a dependency of the TypeScript compiler when you enable TypeScript importHelpers. Any ...
Read more >Could not find module in path: '@babylonjs/core/tslib.es6.js'
Error : Build failed with 40 errors: node_modules/@babylonjs/gui/2D/controls/checkbox.js:1:27: ERROR: Could not resolve "@babylonjs/core/tslib.
Read more >This syntax requires an imported helper but module 'tslib ...
To solve the error "This syntax requires an imported helper but module 'tslib' cannot be found", install tslib by running npm install -D...
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 FreeTop 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
Top GitHub Comments
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"
intsconfig.json
. It’s a bug IMHO.The offer #84 will solve the problem