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.

modules/index.js should re-export tslib.es6.js instead of tslib.js

See original GitHub issue

Unless I’m misunderstanding something, I’d expect modules/index.js to re-export ../tslib.es6.js instead of ../tslib.js.

https://github.com/microsoft/tslib/blob/master/modules/index.js#L1

I’m basing my statement on the understanding that exports['.']['import'] should point to some “modern” code:

https://github.com/microsoft/tslib/blob/master/package.json#L29-L34

(The reason I’m opening this issue is that I’m facing some problem in combination with Vite which is based on ESM.)

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:1
  • Comments:21 (6 by maintainers)

github_iconTop GitHub Comments

6reactions
yyx990803commented, Jan 20, 2021

@DanielRosenwasser would love an eye on this.

From Vite resolver’s perspective, module is a non-standard condition in exports, so it resolves to the import condition… which points to an ESM file that imports a UMD file (!!!). This does work in Node.js because Node allows ESM to import commonjs files… however for a native-ESM dev server like Vite, it assumes entries specified by the import condition to only contain valid ESM all the way through.

On the other hand, why doesn’t the import condition simply point to tslib.es6.js? What is the point of having the modules/index.js indirection?

This can be fixed on Vite’s front by also checking the module condition in exports field, but that is technically non-standard 😕

3reactions
wiessoncommented, Oct 5, 2021
Read more comments on GitHub >

github_iconTop Results From Across the Web

SyntaxError: Unexpected token 'export' happens at tslib.es6.js ...
After renaming the tslib.es6.js to tslib.mjs the error is gone, but this is no solution. It should work after any yarn install.
Read more >
ECMAScript modules | Node.js v19.3.0 Documentation
Instead, use import() to load an ES module from a CommonJS module. CommonJS Namespaces#. CommonJS modules consist of a module.exports object which can...
Read more >
Best Practice Tips for Writing Your JS Modules
Author in ESM. You should write your modules in ESM format (or Typescript if you'd like) and have bundler output them to CJS...
Read more >
Solved — Rxjs TypeError: Cannot destructure property '__ ...
es6.js instead of tslib.js ? Solution. The solution is simple. We can add a key alias in our Webpack ...
Read more >
"Fossies" - the Fresh Open Source Software Archive
Member "src/node_modules/tslib/package.json" (26 Oct 1985, 1140 Bytes) of package ... 25 "module": "tslib.es6.js", 26 "jsnext:main": "tslib.es6.js", ...
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