Skip to content

Commit 26ba647

Browse files
authored
Merge branch 'master' into master
2 parents 1c7e2d6 + 7522d14 commit 26ba647

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+20559
-2200
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ dist/*
66
!/dist/v5
77
!/dist/v6
88
!/dist/v7
9+
!/dist/v8
910

1011
/tmp
1112
/out-tsc

.husky/pre-commit

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
#!/bin/sh
22
. "$(dirname "$0")/_/husky.sh"
33

4-
npx lint-staged
4+
npx --no-install lint-staged

.nvmrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
16.15.0
1+
16.16.0

content/cli/overview.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,5 +93,4 @@ See [usage](/cli/usages) for detailed descriptions for each command.
9393
| `build` | | Compiles an application or workspace into an output folder. |
9494
| `start` | | Compiles and runs an application (or default project in a workspace). |
9595
| `add` | | Imports a library that has been packaged as a **nest library**, running its install schematic. |
96-
| `update` | `u` | Update `@nestjs` dependencies in the `package.json` `"dependencies"` list to their `@latest` version. |
9796
| `info` | `i` | Displays information about installed nest packages and other helpful system info. |

content/discover/who-uses.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,10 @@
194194
{
195195
"logo": "/assets/logo/fuse-logo.svg",
196196
"url": "https://fuseautotech.com"
197+
},
198+
{
199+
"logo": "/assets/logo/amplication.svg",
200+
"url": "https://amplication.com"
197201
}
198202
],
199203
"Body": [

content/faq/errors.md

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,49 @@ Potential solutions:
1717
})
1818
```
1919
20-
The most common culprit of the error, is not having the `provider` in the module's `providers` array. Please make sure that the provider is indeed in the `providers` array and following [standard NestJS provider practices](/fundamentals/custom-providers#di-fundamentals).
20+
The most common culprit of the error, is not having the `<provider>` in the module's `providers` array. Please make sure that the provider is indeed in the `providers` array and following [standard NestJS provider practices](/fundamentals/custom-providers#di-fundamentals).
2121

2222
There are a few gotchas, that are common. One is putting a provider in an `imports` array. If this is the case, the error will have the provider's name where `<module>` should be.
2323
24-
If you run across this error while developing, take a look at the module mentioned in the error message and look at its `providers`. For each provider in the `providers` array, make sure the module has access to all of the dependencies. Often times, `providers` are duplicated in a "Feature Module" and a "Root Module" which means Nest will try to instantiate the provider twice. More than likely, the module containing the `provider` being duplicated should be added in the "Root Module"'s `imports` array instead.
24+
If you run across this error while developing, take a look at the module mentioned in the error message and look at its `providers`. For each provider in the `providers` array, make sure the module has access to all of the dependencies. Often times, `providers` are duplicated in a "Feature Module" and a "Root Module" which means Nest will try to instantiate the provider twice. More than likely, the module containing the `<provider>` being duplicated should be added in the "Root Module"'s `imports` array instead.
2525

26-
If the `unknown_token` above is the string `dependency`, you might have a circular file import. This is different from the [circular dependency](./errors.md#circular-dependency-error) below because instead of having providers depend on each other in their constructors, it just means that two files end up importing each other. A common case would be a module file declaring a token and importing a provider, and the provider import the token constant from the module file. If you are using barrel files, ensure that your barrel imports do not end up creating these circular imports as well.
26+
If the `<unknown_token>` above is the string `dependency`, you might have a circular file import. This is different from the [circular dependency](/faq/common-errors#circular-dependency-error) below because instead of having providers depend on each other in their constructors, it just means that two files end up importing each other. A common case would be a module file declaring a token and importing a provider, and the provider import the token constant from the module file. If you are using barrel files, ensure that your barrel imports do not end up creating these circular imports as well.
27+
28+
If the `<unknown_token>` above is the string `Object`, it means that you're injecting using an type/interface without a proper provider's token. To fix that, make sure you're importing the class reference or use a custom token with `@Inject()` decorator. Read the [custom providers page](/fundamentals/custom-providers).
29+
30+
Also, make sure you didn't end up injecting the provider on itself because self-injections are not allowed in NestJS. When this happens, `<unknown_token>` will likely be equal to `<provider>`.
31+
32+
If you are in a **monorepo setup**, you may face the same error as above but for core provider called `ModuleRef` as a `<unknown_token>`:
33+
34+
```bash
35+
Nest can't resolve dependencies of the <provider> (?).
36+
Please make sure that the argument ModuleRef at index [<index>] is available in the <module> context.
37+
...
38+
```
39+
40+
This likely happens when your project end up loading two Node modules of the package `@nestjs/core`, like this:
41+
42+
```text
43+
.
44+
├── package.json
45+
├── apps
46+
│ └── api
47+
│ └── node_modules
48+
│ └── @nestjs/bull
49+
│ └── node_modules
50+
│ └── @nestjs/core
51+
└── node_modules
52+
├── (other packages)
53+
└── @nestjs/core
54+
```
55+
56+
Solutions:
57+
58+
- For **Yarn** Workspaces, use the [nohoist feature](https://classic.yarnpkg.com/blog/2018/02/15/nohoist) to prevent hoisting the package `@nestjs/core`.
2759
2860
#### "Circular dependency" error
2961
30-
Occasionally you'll find it difficult to avoid [circular dependencies](/fundamentals/circular-dependency) in your application. You'll need to take some steps to help Nest resolve these. Errors that arise from circular dependencies look like this:
62+
Occasionally you'll find it difficult to avoid [circular dependencies](https://docs.nestjs.com/fundamentals/circular-dependency) in your application. You'll need to take some steps to help Nest resolve these. Errors that arise from circular dependencies look like this:
3163
3264
```bash
3365
Nest cannot create the <module> instance.

content/faq/hybrid-application.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ const microserviceTcp = app.connectMicroservice<MicroserviceOptions>({
2727
const microserviceRedis = app.connectMicroservice<MicroserviceOptions>({
2828
transport: Transport.REDIS,
2929
options: {
30-
url: 'redis://localhost:6379',
30+
host: 'localhost',
31+
port: 6379,
3132
},
3233
});
3334

@@ -70,7 +71,10 @@ By default a hybrid application will not inherit global pipes, interceptors, gua
7071
To inherit these configuration properties from the main application, set the `inheritAppConfig` property in the second argument (an optional options object) of the `connectMicroservice()` call, as follow:
7172

7273
```typescript
73-
const microservice = app.connectMicroservice({
74-
transport: Transport.TCP
75-
}, { inheritAppConfig: true });
74+
const microservice = app.connectMicroservice(
75+
{
76+
transport: Transport.TCP,
77+
},
78+
{ inheritAppConfig: true },
79+
);
7680
```

content/faq/raw-body.md

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
### Raw body
2+
3+
One of the most common use-case for having access to the raw request body is performing webhook signature verifications. Usually to perform webhook signature validations the unserialized request body is required to calculate an HMAC hash.
4+
5+
#### Use with Express
6+
7+
First enable the option when creating your Nest Express application:
8+
9+
```typescript
10+
const app = await NestFactory.create(AppModule, {
11+
rawBody: true,
12+
});
13+
await app.listen(3000);
14+
```
15+
16+
To access the raw request body in a controller, a convenience interface `RawBodyRequest` is provided to expose a `rawBody` field on the request: use the interface `RawBodyRequest` type:
17+
18+
```typescript
19+
import { Controller, Post, RawBodyRequest, Req } from '@nestjs/common';
20+
import { Request } from 'express';
21+
22+
@Controller('cats')
23+
class CatsController {
24+
@Post()
25+
create(@Req() req: RawBodyRequest<Request>) {
26+
const raw = req.rawBody; // returns a `Buffer`.
27+
}
28+
}
29+
```
30+
31+
#### Use with Fastify
32+
33+
First enable the option when creating your Nest Fastify application:
34+
35+
```typescript
36+
const app = await NestFactory.create<NestFastifyApplication>(
37+
AppModule,
38+
new FastifyAdapter()
39+
{
40+
rawBody: true,
41+
}
42+
);
43+
await app.listen(3000);
44+
```
45+
46+
To access the raw request body in a controller, a convenience interface `RawBodyRequest` is provided to expose a `rawBody` field on the request: use the interface `RawBodyRequest` type:
47+
48+
```typescript
49+
import { Controller, Post, RawBodyRequest, Req } from '@nestjs/common';
50+
import { FastifyRequest } from 'fastify';
51+
52+
@Controller('cats')
53+
class CatsController {
54+
@Post()
55+
create(@Req() req: RawBodyRequest<FastifyRequest>) {
56+
const raw = req.rawBody; // returns a `Buffer`.
57+
}
58+
}
59+
```

0 commit comments

Comments
 (0)