Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support importing from pure ESM packages #7021

Closed
dtinth opened this issue May 3, 2021 · 1 comment
Closed

Support importing from pure ESM packages #7021

dtinth opened this issue May 3, 2021 · 1 comment
Labels
needs triage This issue has not been looked into type: enhancement 🐺

Comments

@dtinth
Copy link

dtinth commented May 3, 2021

Feature Request

Is your feature request related to a problem? Please describe.

A lot of npm packages are now being published as “ESM-only” (shipping only ES modules with no CommonJS version) which makes it no longer requirable from CommonJS code.

I intend to move most of my 1K+ packages to pure ESM within 2021. I’m hoping other package maintainers will follow.

Node.js 10 reached EOL in the end of April, and this month many packages have since been converted to ESM only. Although NestJS uses ESM-style imports in TypeScript, the TypeScript compiler still emits CommonJS modules. Attempting to require such packages will produce a confusing error:

Uncaught:
Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: node_modules/quick-lru/index.js

This is confusing since I’m already using the import statement to import my modules: import QuickLRU from 'quick-lru'. It is not until I look at the compiler’s output to realize that TypeScript converted into require statements.

Describe the solution you'd like

Nest.js should be able to import pure-ESM packages.

There are many ways to solve this problem:

Teachability, Documentation, Adoption, Migration Strategy

This would make developers less confused when importing pure ESM packages from Nest.js projects.

What is the motivation / use case for changing the behavior?

I tried to require quick-lru module which is now ESM only.

@dtinth dtinth added needs triage This issue has not been looked into type: enhancement 🐺 labels May 3, 2021
@kamilmysliwiec
Copy link
Member

I suppose that we'll eventually migrate towards ESM modules, but there's no plan to do this atm. For now, if you must use ESM modules, I'd suggest moving forward with a bundler.

@nestjs nestjs locked and limited conversation to collaborators May 4, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
needs triage This issue has not been looked into type: enhancement 🐺
Projects
None yet
Development

No branches or pull requests

2 participants