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

Ability to create projects with ESM pre-configured #2851

Open
1 task done
vemv opened this issue Dec 27, 2024 · 0 comments
Open
1 task done

Ability to create projects with ESM pre-configured #2851

vemv opened this issue Dec 27, 2024 · 0 comments
Labels

Comments

@vemv
Copy link

vemv commented Dec 27, 2024

Is there an existing issue that is already proposing this?

  • I have searched the existing issues

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

While I understand that NestJS, the framework, is written in CommonJS, and that there's no immediate problem with that, I'm under the impression that users most often want their apps to be set up to consume/emit ESM.

The NestJS CLI creates apps assuming CommonJS, so pure ESM libraries won't work out of the box.

Adapting a NestJS app to work with ESM needs somewhat detailed knowledge, and misc surgery. Some folks don't even know it's possible to make it work, which isn't a good look for NestJS.

Describe the solution you'd like

A new option in the wizard that expressed the user intent to have their project use a ESM compilation pipeline.

The differences seem relatively tiny, and described in this document:

  • Make sure you are using TypeScript 4.7 or later.
  • Add "type": "module" to your package.json.
  • Replace "main": "index.js" with "exports": "./index.js" in your package.json.
  • Update the "engines" field in package.json to Node.js 18: "node": ">=18".
  • Add "module": "node16", "moduleResolution": "node16" to your tsconfig.json. (Example)
  • moduleResolution must be set to node16 or nodenext, NOT node!
  • Use only full relative file paths for imports: import x from '.'; → import x from './index.js';.
  • Remove namespace usage and use export instead.
  • Use the node: protocol for Node.js built-in imports.
  • You must use a .js extension in relative imports even though you're importing .ts files.

Teachability, documentation, adoption, migration strategy

If this option was successfully implemented, perhaps it could eventually become the default?

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

The ability to consume pure ESM libs, and the reduced burden given to users.

@vemv vemv added the feature label Dec 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant