nestjs / nest

A progressive Node.js framework for building efficient, scalable, and enterprise-grade server-side applications with TypeScript/JavaScript 🚀
https://nestjs.com
MIT License
67.57k stars 7.61k forks source link

TypeError: Cannot read properties of null (reading 'preview') #11435

Closed hamzehamirahmadi closed 1 year ago

hamzehamirahmadi commented 1 year ago

Is there an existing issue for this?

Current behavior

I use cucumber for testing.

"@cucumber/cucumber": "^9.1.0",

After running the test, I have this error.

`

this.initialized = true;

const builder: TestingModuleBuilder = Test.createTestingModule({
  imports: [this.appModule],
});

for (const [, provider] of this.providers) {
  await provider.configure(builder, scenario);
}

const module: TestingModule = await builder.compile();
let customAdapter: any = null;

if (this.httpAdapter) {
  customAdapter = new this.httpAdapter.class(this.httpAdapter.options);

  if (customAdapter.register) {
    await customAdapter.register(middie);
  }
}

this.application = module.createNestApplication(customAdapter, { preview: true });

`

TypeError: Cannot read properties of null (reading 'preview') at new NestApplication (node_modules/@nestjs/core/nest-application.js:40:76) at TestingModule.createNestApplication (node_modules/@nestjs/testing/testing-module.js:27:26) at CustomWorld.init (src/abstract.world.ts:78:31) at processTicksAndRejections (node:internal/process/task_queues:95:5) at async CustomWorld.<anonymous> (src/contexts/auth.context.ts:15:7)

Minimum reproduction code

https://github.com/nestjs/nest/blob/d3d28f121df66d577047e78f679975fb3debeec4/packages/core/nest-application.ts#L88 https://github.com/nestjs/nest/blob/d3d28f121df66d577047e78f679975fb3debeec4/packages/core/nest-application-context.ts#L73

Steps to reproduce

No response

Expected behavior

There is no default value for preview. I set it up but there is still a problem.

Package

Other package

No response

NestJS version

9.3.12

Packages versions

Node.js version

18.15.0

In which operating systems have you tested?

Other

No response

micalevisk commented 1 year ago

looks like you didn't upgraded @nestjs/core

What's the output of npx nest info?

hamzehamirahmadi commented 1 year ago

looks like you didn't upgraded @nestjs/core

What's the output of npx nest info?

[System Information] OS Version : Linux 5.15 NodeJS Version : v18.15.0 NPM Version : 9.5.0

[Nest CLI] Nest CLI Version : 9.3.0

[Nest Platform Information] platform-express version : 9.4.0

micalevisk commented 1 year ago

I guess you missed others packages at the [Nest Platform Information] section :thinking:

We need to see the exactly version (not the semver range) of your @nestjs/core and @nestjs/testing

You could check that out by running npm ls @nestjs/core or yarn why @nestjs/core

hamzehamirahmadi commented 1 year ago

I guess you missed others packages at the [Nest Platform Information] section thinking

We need to see the exactly version (not the semver range) of your @nestjs/core and @nestjs/testing

You could check that out by running npm ls @nestjs/core or yarn why @nestjs/core

@pe/cucumber-sdk@6.7.1-beta.18 cucumber-kit ├─┬ @nestjs/platform-express@9.4.0 │ └── @nestjs/core@9.4.0 ├─┬ @pe/dev-kit@3.0.6 │ └─┬ @nestjs/testing@9.4.0 │ └── @nestjs/core@9.4.0 deduped └─┬ @pe/nest-kit@10.3.0-beta.14 ├── @nestjs/core@9.4.0 deduped ├─┬ @nestjs/microservices@9.4.0 │ └── @nestjs/core@9.4.0 deduped ├─┬ @nestjs/mongoose@9.2.2 │ └── @nestjs/core@9.4.0 deduped ├─┬ @nestjs/platform-fastify@9.4.0 │ └── @nestjs/core@9.4.0 deduped ├─┬ @nestjs/swagger@6.3.0 │ └── @nestjs/core@9.4.0 deduped ├─┬ @nestjs/terminus@9.2.2 │ └── @nestjs/core@9.4.0 deduped └─┬ @nestjs/websockets@9.4.0 └── @nestjs/core@9.4.0 deduped

@nestjs/testing is in my node-modules.

A note: when customAdapter from this.application = module.createNestApplication(customAdapter); I delete it and the error is fixed.

micalevisk commented 1 year ago

looks fine

what about npm ls @nestjs/common?

hamzehamirahmadi commented 1 year ago

looks fine

what about npm ls @nestjs/common?

@pe/cucumber-sdk@6.7.1-beta.20 /cucumber-kit ├─┬ @nestjs/platform-express@9.4.0 │ ├── @nestjs/common@9.4.0 │ └─┬ @nestjs/core@9.4.0 │ └── @nestjs/common@9.4.0 deduped ├─┬ @pe/dev-kit@3.0.6 │ └─┬ @nestjs/testing@9.4.0 │ └── @nestjs/common@9.4.0 deduped ├─┬ @pe/elastic-kit@5.2.0-beta.2 │ └── @nestjs/common@9.4.0 deduped └─┬ @pe/nest-kit@10.3.0-beta.14 ├─┬ @nestjs/axios@2.0.0 │ └── @nestjs/common@9.4.0 deduped ├── @nestjs/common@9.4.0 deduped ├─┬ @nestjs/jwt@9.0.0 │ └── @nestjs/common@9.4.0 deduped ├─┬ @nestjs/microservices@9.4.0 │ └── @nestjs/common@9.4.0 deduped ├─┬ @nestjs/mongoose@9.2.2 │ └── @nestjs/common@9.4.0 deduped ├─┬ @nestjs/passport@9.0.3 │ └── @nestjs/common@9.4.0 deduped ├─┬ @nestjs/platform-fastify@9.4.0 │ └── @nestjs/common@9.4.0 deduped ├─┬ @nestjs/swagger@6.3.0 │ ├── @nestjs/common@9.4.0 deduped │ └─┬ @nestjs/mapped-types@1.2.2 │ └── @nestjs/common@9.4.0 deduped ├─┬ @nestjs/terminus@9.2.2 │ └── @nestjs/common@9.4.0 deduped └─┬ @nestjs/websockets@9.4.0 └── @nestjs/common@9.4.0 deduped

micalevisk commented 1 year ago

I just tested the following using v9.4.0 as well but didn't manage to reproduce your issue. Everything went fine

image

image


Please provide a minimum reproduction repository. You can start from this minimal project.

why reproductions are required

micalevisk commented 1 year ago

I just realized that you're passing null to the first arg of TestingModule#createNestApplication image

which doesn't allow such usage. Instead, use undefined if you want to use the default adapter.

If you ran that code with the strict null check mode of typescript, you'd get a compile time error btw.