Skip to content

Commit

Permalink
docs: add faq section with info about nestjs usage
Browse files Browse the repository at this point in the history
re #173
  • Loading branch information
Andrew Stacy committed Oct 1, 2024
1 parent b0a492c commit 05054c9
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/.vuepress/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ export default defineUserConfig({
{ text: 'Getting Started', link: '/getting-started/introduction' },
{ text: 'Reference Manual', link: '/reference/introduction' },
{ text: 'Plugins', link: '/plugins' },
{ text: "FAQ's", link: '/faqs' },
{ text: 'v1.x', link: 'https://v1.adzejs.com/' },
],
sidebar: {
Expand Down
49 changes: 49 additions & 0 deletions docs/faqs.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Frequently Asked Questions

On this page we hope to document frequently asked questions in regards to using the adze library.

## How can I make Adze work with NestJS?

### Problem

"When installing Adze in NestJS I get the following error:"

```bash
Error [ERR_REQUIRE_ESM]: require() of ES Module /Users/andrewstacy/Projects/personal/adze/dist/index.js from /Users/andrewstacy/Projects/personal/project-name/dist/logger.js not supported.
```

### Solution

NestJS currently does not support importing of ES Modules directly. There is currently an
[open PR on GitHub](https://github.com/nestjs/nest/pull/8736) to resolve this.

There are currently two preferred options for working around this limitation:

#### Use Experimental Require Module Flag

The easiest way to work around this issue is to use the node `--experimental-require-module` flag.
Keep in mind that this will only work with **node version >= 22.x** and it is an experimental
feature that can change at any time with new node versions.

Change your nestjs scripts to look like this:

```json
{
"scripts": {
"start": "nest start -e 'node --experimental-require-module'",
"start:dev": "nest start --watch -e 'node --experimental-require-module'",
"start:debug": "nest start --debug --watch -e 'node --experimental-require-module'",
"start:prod": "node --experimental-require-module dist/main"
}
}
```

#### Use Helpers

This method is a bit safer, but is also quite ugly. It requires the use of the dynamic import
function with means that you'll have to await the function each time you want a copy of your adze
logger.

More information about this method can be found at this StackOverflow post:

[https://stackoverflow.com/questions/74830166/unable-to-import-esm-module-in-nestjs](https://stackoverflow.com/questions/74830166/unable-to-import-esm-module-in-nestjs)

0 comments on commit 05054c9

Please sign in to comment.