@nestjs/core 11.1.6 → 11.1.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/Readme.md CHANGED
@@ -8,7 +8,7 @@
8
8
  <p align="center">A progressive <a href="https://nodejs.org" target="_blank">Node.js</a> framework for building efficient and scalable server-side applications.</p>
9
9
  <p align="center">
10
10
  <a href="https://www.npmjs.com/~nestjscore" target="_blank"><img src="https://img.shields.io/npm/v/@nestjs/core.svg" alt="NPM Version" /></a>
11
- <a href="https://www.npmjs.com/~nestjscore" target="_blank"><img src="https://img.shields.io/npm/l/@nestjs/core.svg" alt="Package License" /></a>
11
+ <a href="https://github.com/nestjs/nest/blob/master/LICENSE" target="_blank"><img src="https://img.shields.io/npm/l/@nestjs/core.svg" alt="Package License" /></a>
12
12
  <a href="https://www.npmjs.com/~nestjscore" target="_blank"><img src="https://img.shields.io/npm/dm/@nestjs/common.svg" alt="NPM Downloads" /></a>
13
13
  <a href="https://circleci.com/gh/nestjs/nest" target="_blank"><img src="https://img.shields.io/circleci/build/github/nestjs/nest/master" alt="CircleCI" /></a>
14
14
  <a href="https://discord.gg/G7Qnnhy" target="_blank"><img src="https://img.shields.io/badge/discord-online-brightgreen.svg" alt="Discord"/></a>
@@ -78,10 +78,7 @@ Nest is an MIT-licensed open source project. It can grow thanks to the sponsors
78
78
  </tr>
79
79
  <tr>
80
80
  <td><a href="https://snyk.co/nestjs" target="_blank"><img src="https://nestjs.com/img/logos/snyk-logo-black.png" width="185" valign="middle" /></a></td>
81
- <td><a href="https://fuseautotech.com/" target="_blank"><img src="https://nestjs.com/img/logos/fuse-logo.svg" width="105" valign="middle" /></a></td>
82
- <td><a href="https://ridicorp.com/career/" target="_blank"><img src="https://nestjs.com/img/logos/ridi-logo.svg" width="105" valign="middle" /></a></td>
83
81
  <td><a href="https://www.movavi.com/imovie-for-windows.html" target="_blank"><img src="https://nestjs.com/img/logos/movavi-logo.svg" width="105" valign="middle" /></a></td>
84
- <td><a href="https://skunk.team" target="_blank"><img src="https://nestjs.com/img/logos/skunk-logo.png" height="60" valign="middle" /></a></td>
85
82
  </tr>
86
83
  </table>
87
84
 
@@ -91,10 +88,10 @@ Nest is an MIT-licensed open source project. It can grow thanks to the sponsors
91
88
  <tr>
92
89
  <td><a href="https://www.mercedes-benz.com/" target="_blank"><img src="https://nestjs.com/img/logos/mercedes-logo.png" width="100" valign="middle" /></a></td>
93
90
  <td><a href="https://www.dinii.jp/" target="_blank"><img src="https://nestjs.com/img/logos/dinii-logo.png" width="65" valign="middle" /></a></td>
94
- <td><a href="https://bloodycase.com/?promocode=NEST" target="_blank"><img src="https://nestjs.com/img/logos/bloodycase-logo.png" width="65" valign="middle" /></a></td>
95
91
  <td><a href="https://handsontable.com/docs/react-data-grid/?utm_source=NestJS_GH&utm_medium=sponsorship&utm_campaign=library_sponsorship_2024" target="_blank"><img src="https://nestjs.com/img/logos/handsontable-dark-logo.svg#2" width="150" valign="middle" /></a></td>
96
92
  <td align="center" valign="middle"><a href="https://www.itflashcards.com/" target="_blank"><img src="https://nestjs.com/img/logos/it_flashcards-logo.png" width="170" valign="middle" /></a></td>
97
93
  <td align="center" valign="middle"><a href="https://arcjet.com/?ref=nestjs" target="_blank"><img src="https://nestjs.com/img/logos/arcjet-logo.svg" width="170" valign="middle" /></a></td>
94
+ <td align="center" valign="middle"><a href="https://crawljobs.com" target="_blank"><img src="https://nestjs.com/img/logos/crawljobs-logo.svg" width="130" valign="middle" /></a></td>
98
95
  </tr>
99
96
  </table>
100
97
 
@@ -118,19 +115,16 @@ Nest is an MIT-licensed open source project. It can grow thanks to the sponsors
118
115
  <td align="center" valign="middle"><a href="https://triplecore.io" target="_blank"><img src="https://nestjs.com/img/logos/triplecore-logo.svg" width="50" valign="middle" /></a></td>
119
116
  </tr>
120
117
  <tr>
121
- <td align="center" valign="middle"><a href="https://thecasinowizard.com/bonuses/no-deposit-bonuses/" target="_blank"><img src="https://nestjs.com/img/logos/casinowizard-logo.png" width="120" valign="middle" /></a></td>
122
118
  <td align="center" valign="middle"><a href="https://polygon-software.ch/" target="_blank"><img src="https://nestjs.com/img/logos/polygon-logo.svg" width="120" valign="middle" /></a></td>
123
119
  <td align="center" valign="middle"><a href="https://boringowl.io/" target="_blank"><img src="https://nestjs.com/img/logos/boringowl-logo.svg" width="120" valign="middle" /></a></td>
124
120
  <td align="center" valign="middle"><a href="https://nordbot.app/" target="_blank"><img src="https://nestjs.com/img/logos/nordbot-logo.png" width="120" valign="middle" /></a></td>
125
121
  <td align="center" valign="middle"><a href="https://doppio.sh/" target="_blank"><img src="https://nestjs.com/img/logos/dopiosh-logo.png" width="50" valign="middle" /></a></td>
126
122
  <td align="center" valign="middle"><a href="https://www.hingehealth.com/" target="_blank"><img src="https://nestjs.com/img/logos/hinge-health-logo.svg" width="100" valign="middle" /></a></td>
123
+ <td align="center" valign="middle"><a href="https://www.tripoffice.com/" target="_blank"><img src="https://nestjs.com/img/logos/tripoffice-logo.png" width="140" valign="middle" /></a></td>
127
124
  </tr>
128
125
  <tr>
129
- <td align="center" valign="middle"><a href="https://julienferand.dev/" target="_blank"><img src="https://nestjs.com/img/logos/julienferand-logo.jpeg" width="55" valign="middle" /></a></td>
130
- <td align="center" valign="middle"><a href="https://www.tripoffice.com/" target="_blank"><img src="https://nestjs.com/img/logos/tripoffice-logo.png" width="140" valign="middle" /></a></td>
131
126
  <td align="center" valign="middle"><a href="https://solcellsforetag.se/" target="_blank"><img src="https://nestjs.com/img/logos/solcellsforetag-logo.svg" width="140" valign="middle" /></a></td>
132
127
  <td align="center" valign="middle"><a href="https://www.route4me.com/" target="_blank"><img src="https://nestjs.com/img/logos/route4me-logo.svg" width="100" valign="middle" /></a></td>
133
- <td align="center" valign="middle"><a href="https://www.slotsup.com/" target="_blank"><img src="https://nestjs.com/img/logos/slotsup-logo.png" width="60" valign="middle" /></a></td>
134
128
  </tr>
135
129
  </table>
136
130
 
@@ -48,10 +48,31 @@ const UNKNOWN_DEPENDENCIES_MESSAGE = (type, unknownDependencyContext, moduleRef)
48
48
  const { index, name, dependencies, key } = unknownDependencyContext;
49
49
  const moduleName = getModuleName(moduleRef);
50
50
  const dependencyName = getDependencyName(name, 'dependency');
51
- const potentialSolutions =
52
- // If module's name is well defined
53
- moduleName !== 'current'
54
- ? `\n
51
+ const isImportTypeIssue = !(0, shared_utils_1.isNil)(index) &&
52
+ dependencies &&
53
+ (dependencies[index] === undefined ||
54
+ dependencies[index] === Object ||
55
+ (typeof dependencies[index] === 'function' &&
56
+ dependencies[index].name === 'Object'));
57
+ let potentialSolutions;
58
+ if (isImportTypeIssue) {
59
+ potentialSolutions = `\n
60
+ Potential solutions:
61
+ - The dependency at index [${index}] appears to be undefined at runtime
62
+ - This commonly occurs when using 'import type' instead of 'import' for injectable classes
63
+ - Check your imports and change:
64
+ ❌ import type { SomeService } from './some.service';
65
+ ✅ import { SomeService } from './some.service';
66
+ - Ensure the imported class is decorated with @Injectable() or is a valid provider
67
+ - If using dynamic imports, ensure the class is available at runtime, not just for type checking
68
+
69
+ For more common dependency resolution issues, see: https://docs.nestjs.com/faq/common-errors`;
70
+ }
71
+ else {
72
+ potentialSolutions =
73
+ // If module's name is well defined
74
+ moduleName !== 'current'
75
+ ? `\n
55
76
  Potential solutions:
56
77
  - Is ${moduleName} a valid NestJS module?
57
78
  - If ${dependencyName} is a provider, is it part of the current ${moduleName}?
@@ -59,15 +80,18 @@ Potential solutions:
59
80
  @Module({
60
81
  imports: [ /* the Module containing ${dependencyName} */ ]
61
82
  })
62
- `
63
- : `\n
83
+
84
+ For more common dependency resolution issues, see: https://docs.nestjs.com/faq/common-errors`
85
+ : `\n
64
86
  Potential solutions:
65
87
  - If ${dependencyName} is a provider, is it part of the current Module?
66
88
  - If ${dependencyName} is exported from a separate @Module, is that module imported within Module?
67
89
  @Module({
68
90
  imports: [ /* the Module containing ${dependencyName} */ ]
69
91
  })
70
- `;
92
+
93
+ For more common dependency resolution issues, see: https://docs.nestjs.com/faq/common-errors`;
94
+ }
71
95
  let message = `Nest can't resolve dependencies of the ${type.toString()}`;
72
96
  if ((0, shared_utils_1.isNil)(index)) {
73
97
  message += `. Please make sure that the "${key.toString()}" property is available in the current context.${potentialSolutions}`;
@@ -77,7 +101,7 @@ Potential solutions:
77
101
  dependenciesName[index] = '?';
78
102
  message += ` (`;
79
103
  message += dependenciesName.join(', ');
80
- message += `). Please make sure that the argument ${dependencyName} at index [${index}] is available in the ${moduleName} context.`;
104
+ message += `). Please make sure that the argument ${isImportTypeIssue ? 'dependency' : dependencyName} at index [${index}] is available in the ${isImportTypeIssue ? 'current' : moduleName} context.`;
81
105
  message += potentialSolutions;
82
106
  return message;
83
107
  };
@@ -125,6 +149,8 @@ const UNKNOWN_EXPORT_MESSAGE = (token = 'item', module) => {
125
149
 
126
150
  Possible Solutions:
127
151
  - Is ${token} part of the relevant providers/imports within ${module}?
152
+
153
+ For more common dependency resolution issues, see: https://docs.nestjs.com/faq/common-errors
128
154
  `;
129
155
  };
130
156
  exports.UNKNOWN_EXPORT_MESSAGE = UNKNOWN_EXPORT_MESSAGE;
@@ -82,6 +82,14 @@ export declare class Injector {
82
82
  loadCtorMetadata(metadata: InstanceWrapper<any>[], contextId: ContextId, inquirer?: InstanceWrapper, parentInquirer?: InstanceWrapper): Promise<any[]>;
83
83
  loadPropertiesMetadata(metadata: PropertyMetadata[], contextId: ContextId, inquirer?: InstanceWrapper): Promise<PropertyDependency[]>;
84
84
  private getInquirerId;
85
+ /**
86
+ * For nested TRANSIENT dependencies (TRANSIENT -> TRANSIENT) in non-static contexts,
87
+ * returns parentInquirer to ensure each parent TRANSIENT gets its own instance.
88
+ * This is necessary because in REQUEST/DURABLE scopes, the same TRANSIENT wrapper
89
+ * can be used by multiple parents, causing nested TRANSIENTs to be shared incorrectly.
90
+ * For non-TRANSIENT -> TRANSIENT, returns inquirer (current wrapper being created).
91
+ */
92
+ private getEffectiveInquirer;
85
93
  private resolveScopedComponentHost;
86
94
  private isInquirerRequest;
87
95
  private isInquirer;
@@ -111,7 +111,6 @@ class Injector {
111
111
  return settlementSignal;
112
112
  }
113
113
  async resolveConstructorParams(wrapper, moduleRef, inject, callback, contextId = constants_2.STATIC_CONTEXT, inquirer, parentInquirer) {
114
- const inquirerId = this.getInquirerId(inquirer);
115
114
  const metadata = wrapper.getCtorMetadata();
116
115
  if (metadata && contextId !== constants_2.STATIC_CONTEXT) {
117
116
  const deps = await this.loadCtorMetadata(metadata, contextId, inquirer, parentInquirer);
@@ -145,8 +144,9 @@ class Injector {
145
144
  * and result in undefined / null injection.
146
145
  */
147
146
  await paramBarrier.signalAndWait();
148
- const paramWrapperWithInstance = await this.resolveComponentHost(moduleRef, paramWrapper, contextId, inquirer);
149
- const instanceHost = paramWrapperWithInstance.getInstanceByContextId(this.getContextId(contextId, paramWrapperWithInstance), inquirerId);
147
+ const effectiveInquirer = this.getEffectiveInquirer(paramWrapper, inquirer, parentInquirer, contextId);
148
+ const paramWrapperWithInstance = await this.resolveComponentHost(moduleRef, paramWrapper, contextId, effectiveInquirer);
149
+ const instanceHost = paramWrapperWithInstance.getInstanceByContextId(this.getContextId(contextId, paramWrapperWithInstance), this.getInquirerId(effectiveInquirer));
150
150
  if (!instanceHost.isResolved && !paramWrapperWithInstance.forwardRef) {
151
151
  isResolved = false;
152
152
  }
@@ -357,12 +357,12 @@ class Injector {
357
357
  * and result in undefined / null injection.
358
358
  */
359
359
  await propertyBarrier.signalAndWait();
360
- const paramWrapperWithInstance = await this.resolveComponentHost(moduleRef, paramWrapper, contextId, inquirer);
360
+ const effectivePropertyInquirer = this.getEffectiveInquirer(paramWrapper, inquirer, parentInquirer, contextId);
361
+ const paramWrapperWithInstance = await this.resolveComponentHost(moduleRef, paramWrapper, contextId, effectivePropertyInquirer);
361
362
  if (!paramWrapperWithInstance) {
362
363
  return undefined;
363
364
  }
364
- const inquirerId = this.getInquirerId(inquirer);
365
- const instanceHost = paramWrapperWithInstance.getInstanceByContextId(this.getContextId(contextId, paramWrapperWithInstance), inquirerId);
365
+ const instanceHost = paramWrapperWithInstance.getInstanceByContextId(this.getContextId(contextId, paramWrapperWithInstance), this.getInquirerId(effectivePropertyInquirer));
366
366
  return instanceHost.instance;
367
367
  }
368
368
  catch (err) {
@@ -417,11 +417,13 @@ class Injector {
417
417
  ? Object.assign(instanceHost.instance, new metatype(...instances))
418
418
  : new metatype(...instances);
419
419
  instanceHost.instance = this.instanceDecorator(instanceHost.instance);
420
+ instanceHost.isConstructorCalled = true;
420
421
  }
421
422
  else if (isInContext) {
422
423
  const factoryReturnValue = targetMetatype.metatype(...instances);
423
424
  instanceHost.instance = await factoryReturnValue;
424
425
  instanceHost.instance = this.instanceDecorator(instanceHost.instance);
426
+ instanceHost.isConstructorCalled = true;
425
427
  }
426
428
  instanceHost.isResolved = true;
427
429
  return instanceHost.instance;
@@ -446,8 +448,11 @@ class Injector {
446
448
  }
447
449
  async loadCtorMetadata(metadata, contextId, inquirer, parentInquirer) {
448
450
  const hosts = await Promise.all(metadata.map(async (item) => this.resolveScopedComponentHost(item, contextId, inquirer, parentInquirer)));
449
- const inquirerId = this.getInquirerId(inquirer);
450
- return hosts.map(item => item?.getInstanceByContextId(this.getContextId(contextId, item), inquirerId).instance);
451
+ return hosts.map((item, index) => {
452
+ const dependency = metadata[index];
453
+ const effectiveInquirer = this.getEffectiveInquirer(dependency, inquirer, parentInquirer, contextId);
454
+ return item?.getInstanceByContextId(this.getContextId(contextId, item), this.getInquirerId(effectiveInquirer)).instance;
455
+ });
451
456
  }
452
457
  async loadPropertiesMetadata(metadata, contextId, inquirer) {
453
458
  const dependenciesHosts = await Promise.all(metadata.map(async ({ wrapper: item, key }) => ({
@@ -464,10 +469,25 @@ class Injector {
464
469
  getInquirerId(inquirer) {
465
470
  return inquirer ? inquirer.id : undefined;
466
471
  }
472
+ /**
473
+ * For nested TRANSIENT dependencies (TRANSIENT -> TRANSIENT) in non-static contexts,
474
+ * returns parentInquirer to ensure each parent TRANSIENT gets its own instance.
475
+ * This is necessary because in REQUEST/DURABLE scopes, the same TRANSIENT wrapper
476
+ * can be used by multiple parents, causing nested TRANSIENTs to be shared incorrectly.
477
+ * For non-TRANSIENT -> TRANSIENT, returns inquirer (current wrapper being created).
478
+ */
479
+ getEffectiveInquirer(dependency, inquirer, parentInquirer, contextId) {
480
+ return dependency?.isTransient &&
481
+ inquirer?.isTransient &&
482
+ parentInquirer &&
483
+ contextId !== constants_2.STATIC_CONTEXT
484
+ ? parentInquirer
485
+ : inquirer;
486
+ }
467
487
  resolveScopedComponentHost(item, contextId, inquirer, parentInquirer) {
468
488
  return this.isInquirerRequest(item, parentInquirer)
469
489
  ? parentInquirer
470
- : this.resolveComponentHost(item.host, item, contextId, inquirer);
490
+ : this.resolveComponentHost(item.host, item, contextId, this.getEffectiveInquirer(item, inquirer, parentInquirer, contextId));
471
491
  }
472
492
  isInquirerRequest(item, parentInquirer) {
473
493
  return item.isTransient && item.name === inquirer_1.INQUIRER && parentInquirer;
@@ -25,6 +25,7 @@ export interface InstancePerContext<T> {
25
25
  isResolved?: boolean;
26
26
  isPending?: boolean;
27
27
  donePromise?: Promise<unknown>;
28
+ isConstructorCalled?: boolean;
28
29
  }
29
30
  export interface PropertyMetadata {
30
31
  key: symbol | string;
@@ -266,7 +266,11 @@ class InstanceWrapper {
266
266
  const instances = [...this.transientMap.values()];
267
267
  return (0, iterare_1.iterate)(instances)
268
268
  .map(item => item.get(constants_1.STATIC_CONTEXT))
269
- .filter(item => !!item)
269
+ .filter(item => {
270
+ // Only return items where constructor has been actually called
271
+ // This prevents calling lifecycle hooks on non-instantiated transient services
272
+ return !!(item && item.isConstructorCalled);
273
+ })
270
274
  .toArray();
271
275
  }
272
276
  mergeWith(provider) {
package/nest-factory.js CHANGED
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.NestFactory = exports.NestFactoryStatic = void 0;
4
+ const console_logger_service_1 = require("@nestjs/common/services/console-logger.service");
4
5
  const logger_service_1 = require("@nestjs/common/services/logger.service");
5
6
  const load_package_util_1 = require("@nestjs/common/utils/load-package.util");
6
7
  const shared_utils_1 = require("@nestjs/common/utils/shared.utils");
@@ -154,10 +155,16 @@ class NestFactoryStatic {
154
155
  if (!options) {
155
156
  return;
156
157
  }
157
- const { logger, bufferLogs, autoFlushLogs } = options;
158
+ const { logger, bufferLogs, autoFlushLogs, forceConsole } = options;
158
159
  if (logger !== true && !(0, shared_utils_1.isNil)(logger)) {
159
160
  logger_service_1.Logger.overrideLogger(logger);
160
161
  }
162
+ else if (forceConsole) {
163
+ // If no custom logger is provided but forceConsole is true,
164
+ // create a ConsoleLogger with forceConsole option
165
+ const consoleLogger = new console_logger_service_1.ConsoleLogger({ forceConsole: true });
166
+ logger_service_1.Logger.overrideLogger(consoleLogger);
167
+ }
161
168
  if (bufferLogs) {
162
169
  logger_service_1.Logger.attachBuffer();
163
170
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nestjs/core",
3
- "version": "11.1.6",
3
+ "version": "11.1.8",
4
4
  "description": "Nest - modern, fast, powerful node.js web framework (@core)",
5
5
  "author": "Kamil Mysliwiec",
6
6
  "license": "MIT",
@@ -34,12 +34,12 @@
34
34
  "@nuxt/opencollective": "0.4.1",
35
35
  "fast-safe-stringify": "2.1.1",
36
36
  "iterare": "1.2.1",
37
- "path-to-regexp": "8.2.0",
37
+ "path-to-regexp": "8.3.0",
38
38
  "tslib": "2.8.1",
39
39
  "uid": "2.0.2"
40
40
  },
41
41
  "devDependencies": {
42
- "@nestjs/common": "11.1.6"
42
+ "@nestjs/common": "11.1.8"
43
43
  },
44
44
  "peerDependencies": {
45
45
  "@nestjs/common": "^11.0.0",