ESM-only oidc-provider and NestJS #1249
Replies: 4 comments 14 replies
-
@Gamote how can I set it up with ExpressJS? |
Beta Was this translation helpful? Give feedback.
-
There's no going back to CJS for this module. That being said, be on a lookout for nodejs/node#51977 to land in the supported Node.js release lines. With Refs: https://joyeecheung.github.io/blog/2024/03/18/require-esm-in-node-js/ |
Beta Was this translation helpful? Give feedback.
-
Hi @Gamote I tried to repeat your solution, but I got an error:
|
Beta Was this translation helpful? Give feedback.
-
Hello everyone! I’d like to share that you can use the nest-oidc-provider package to integrate Hope this helps! |
Beta Was this translation helpful? Give feedback.
-
First of all, amazing package! 💯 Huge thanks to all the contributors for your time put into this project. 🙏🏼
What is up?
As you all know since
v8.x
this package is delivered as ESM only. NestJS being a CommonJS only (at least for the foreseeable future).I assume that there is no option for the package to also deliver CommonJS (
?
) so I had to find a solution. Solution that I want to share with you, hopping that it will help developers and/or maybe it can be improved.Summary of the issue
oidc-provider
is a full ESM package since version 8 (release)Read more about it:
import()
when module isCommonJS
microsoft/TypeScript#43329Solution
The solution was to have the module asynchronously be imported. Then we created an injectable provider that will await the import of the
oidc-provider
. This is so we don't have be forced to await it down the line. For example if we want to use it in a constructor. Code:Usage
Add the provider in the module
Use it in the service
Beta Was this translation helpful? Give feedback.
All reactions