You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Windows users who are using TypeScript version 4.9 and up may encounter this problem.
2
+
This happens when you're trying to run your application in watch mode, e.g `npm run start:dev` and see an endless loop of the log messages:
3
+
```text
4
+
XX:XX:XX AM - File change detected. Starting incremental compilation...
5
+
XX:XX:XX AM - Found 0 errors. Watching for file changes.
6
+
```
7
+
When you're using the NestJS CLI to start your application in watch mode it is done by calling `tsc --watch`, and as of version 4.9 of TypeScript, a new strategy for detecting file changes is used which is likely to be the cause of this problem.
8
+
In order to fix this problem, you need to add a setting to your tsconfig.json file after the `"compilerOptions"` option as follows:
9
+
```json
10
+
{
11
+
"watchOptions": {
12
+
"watchFile": "fixedPollingInterval"
13
+
}
14
+
}
15
+
```
16
+
This tells TypeScript to use the polling method for checking for file changes instead of file system events (the new default method), which can cause issues on some machines.
17
+
You can read more about the `"watchFile"` option in TypeScript documentation.
Along with just manually verifying your dependencies are correct, as of Nest 8.1.0 you can set the `NEST_DEBUG` environment variable to a string that resolves as truthy, and get extra logging information while Nest is resolving all the dependencies for the application.
2
+
https://docs.nestjs.com/assets/injector_logs.png
3
+
The string in yellow is the host class of the dependency being injected, the string in blue is the name of the injected dependency, or its injection token, and the string in purple is the module in which the dependency is being searched for. Using this, you can usually trace back the dependency resolution for what's happening and why you're getting dependency injection problems.
The most common error in Nest is failing to resolve provider dependencies.
2
+
The error message usually looks something like this:
3
+
```text
4
+
Nest can't resolve dependencies of the <provider> (?). Please make sure that the argument <unknown_token> at index [<index>] is available in the <module> context.
5
+
6
+
Potential solutions:
7
+
- Is <module> a valid NestJS module?
8
+
- If <unknown_token> is a provider, is it part of the current <module>?
9
+
- If <unknown_token> is exported from a separate @Module, is that module imported within <module>?
10
+
@Module({
11
+
imports: [ /* the Module containing <unknown_token> */ ]
12
+
})
13
+
```
14
+
The most common culprit of the error, is not having the `<provider>` in the module's `providers` array.
15
+
Please make sure that the provider is indeed in the `providers` array and following standard NestJS provider practices.
16
+
17
+
There are a few gotchas, that are common. One is putting a provider in an `imports` array.
18
+
If this is the case, the error will have the provider's name where `<module>` should be.
Please refrain from posting your question in multiple channels, or linking the channel elsewhere.
3
+
If someone knew topic A, they would be in the topic A channel. Asking in irrelevant channels is just spam.
4
+
Please be patient waiting for an answer, it may take time for someone with adequate knowledge to answer your question, furthermore, make sure that your question is well-structured.
0 commit comments