Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Next server type issue(s) #30

Closed
ArrayKnight opened this issue Dec 9, 2019 · 4 comments
Closed

Next server type issue(s) #30

ArrayKnight opened this issue Dec 9, 2019 · 4 comments
Labels
question Further information is requested

Comments

@ArrayKnight
Copy link

ArrayKnight commented Dec 9, 2019

Describe the bug

TS2345: Argument of type 'import(".../node_modules/next/dist/next-server/server/next-server").default' is not assignable to parameter of type 'import(".../node_modules/nest-next/node_modules/next/dist/next-server/server/next-server").default'. Types have separate declarations of a private property 'compression'.

For some reason Nest-Next implements a static version of Next (in a private node_modules) rather than using the installed peer. But that doesn't appear to be the root of the issue, since the two types actually have the same type definition for "compression":

private compression?;

Not sure what the core issue is...

Expected behavior

No type error.

To Reproduce

import 'reflect-metadata'
import { NestFactory } from '@nestjs/core'
import { RenderModule } from 'nest-next'
import Next from 'next'

import { AppModule } from './app.module'
import { configService } from './config.service'

async function bootstrap() {
    const dev = !configService.isProduction()
    const app = Next({ dev })

    await app.prepare()

    const server = await NestFactory.create(AppModule)
    const renderer = server.get(RenderModule)

    // Error is here on "app"
    renderer.register(server, app, { dev, viewsDir: null })

    await server.listen(3000)
}

bootstrap()

Version

  • typescript: 3.7.3
  • next.js: 9.1.4
  • nest: 6.10.8
  • nest-next: 9.1.0
@kyle-mccarthy
Copy link
Owner

This has been a reoccurring issue, and I am not entirely sure what the best way to fix it is. I have included next as a peerDependency, but it's not working as I expected it would.

I'm not very well-versed in how peer deps work and would like to use the user's next-server rather than limiting it to the implementation of the next-server version that it was transpiled with. Maybe you could provide some insight? An easy work around would just for this lib to type the second arg of register as any, but this is a less than ideal solution IMO.

register method: https://github.com/kyle-mccarthy/nest-next/blob/master/lib/render.module.ts#L23

@kyle-mccarthy kyle-mccarthy added the question Further information is requested label Dec 13, 2019
@boenrobot
Copy link
Contributor

boenrobot commented Dec 20, 2019

I think the fact that next is also a required dependency may be the culprit. If the semver versions are incompatible, next-nest will get its own copy of Next, rathert than the main one.

That said, "9.1.4" should be semver compatible to "^9.0.6", so I'm not sure why a separate copy is given... or maybe npm always does it, not just on mismatches... I use yarn, which definetly doesn't do that, but instead hoists compatible deps.

Anyway, as a solution, change it to a devDependency I guess?

@kyle-mccarthy
Copy link
Owner

@boenrobot Yup you are correct -- I had it is a peerDependency + dependency but it actually should be peerDependency + devDependency. I'll just pushed v9.1.1 with the correct package.json @ArrayKnight can you let me know if the new version resolves your issue?

@ArrayKnight
Copy link
Author

Sorry about the delayed response, I was on holiday. I can confirm that this has been fixed. Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants