question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Problem with tslib and ES modules

See original GitHub issue

When 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:closed
  • Created 4 years ago
  • Reactions:4
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
nalplycommented, Dec 30, 2019

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.

0reactions
sla100commented, Jan 12, 2020

The offer #84 will solve the problem

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found