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.

Publish TypeDORM packages in ESM & CJS instead of UMD

See original GitHub issue

Hello,

I am trying to use this nice library in some AWS lambda functions, but I am facing issues with bundling with both esbuild and webpack. Webpack is complaining with:

WARNING in ./node_modules/@typedorm/common/index.js 13:24-31
Critical dependency: require function is used in a way in which dependencies cannot be statically extracted

What is the reason of publishing this library as UMD?

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:24 (10 by maintainers)

github_iconTop GitHub Comments

2reactions
whimzyLivecommented, Mar 24, 2022

@mathieubrd This will get resolved soon and will be available in the Beta channel, latest by the end of the week next week.

Meanwhile, I would suggest skipping the TypeDORM packages from the bundle and installing it as external modules, when running in Lambda.

2reactions
aukevanleeuwencommented, Mar 14, 2022

Thanks for your quick response, and the library in general.

We publish all the modules of this library in UMD so that they can be used in both Nodejs and Browser environments. (cjs and amd).

If I may be so blunt: isn’t that a bit of an old way of thinking about it? By publishing like this you’re essentially making your code un-bundle-able by commonly used bundlers such as esbuild, swc, rollup, .... Webpack does its very best but issues a gazillion Critical warnings such as Critical dependency: require function is used in a way in which dependencies cannot be statically extracted.

I would argue that:

  1. Currently used browsers are more than capable of support ESM as an output format. https://caniuse.com/es6-module. Earliest implementations are from 2017: https://jakearchibald.com/2017/es-modules-in-browsers/ which is 5 years ago.
  2. Nowadays people that are using these kind of libraries in their webapps are inclined to use bundlers such as the earlier mentioned ones. It’s the problem of the user of this library to make sure that the platform that he/she wants to use it in actually supports it. Basically the output target of those bundlers is what matters then right and you don’t have to worry about it.

Doesn’t it make more sense to make your library more bundle-able and tree-shake-able to help progress the web, while still allowing people that really need to support older browsers (but having the burden on them in that case)?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Publish ESM and CJS in a single package
A short tutorial of shipping both ESM and CJS dual formats in a single NPM package.
Read more >
What the heck are CJS, AMD, UMD, and ESM in Javascript?
When CJS imports, it will give you a copy of the imported object. CJS will not work in the browser. It will have...
Read more >
How to Create a Hybrid NPM Module for ESM and ...
Creating a single NPM module that works in all environments.
Read more >
What is the easiest way to pack and publish an npm module?
Bundle it to UMD with rollup (it creates smaller bundles then Webpack ... Publish compiled files as esm + cjs when in package.json...
Read more >
Build a Modern JS Project - #5 Rollup with CJS, ESM & UMD
In this next episode, we'll configure a build setup in our project. Our source code will define React components and export them via...
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