kyle-mccarthy / nest-next

Render Module to add Nextjs support for Nestjs
MIT License
644 stars 91 forks source link

Usage with Nest CLI #76

Open thisismydesign opened 3 years ago

thisismydesign commented 3 years ago

Describe the bug

I'm trying to add Next to my existing NestJS project following the readme and basic example. I'm getting 404 for all pages.

My NestJS project is an example project following the getting started guide, so I imagined the integration to work out of the box. It uses the nest CLI for start and build.

I suspect the pages are not compiled, because I can't find them in the .next folder whereas running the basic example they're there. But I'm not sure how to adapt the existing setup using Nest CLI.

Expected behavior

A description in the readme to explain the usage with Next defaults.

To Reproduce

Repository URL: https://github.com/thisismydesign/nestjs-playground/tree/668dec84d2ff6544a1bc2f57cd874e44e33443f7

Version

Additional context

Initial tsconfig:

{
  "compilerOptions": {
    "module": "commonjs",
    "declaration": true,
    "removeComments": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "allowSyntheticDefaultImports": true,
    "target": "es2017",
    "sourceMap": true,
    "outDir": "./dist",
    "baseUrl": "./",
    "incremental": true
  }

tsconfig updated by Next:

{
  "compilerOptions": {
    "module": "esnext",
    "declaration": true,
    "removeComments": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "allowSyntheticDefaultImports": true,
    "target": "es2017",
    "sourceMap": true,
    "outDir": "./dist",
    "baseUrl": "./",
    "incremental": true,
    "lib": [
      "dom",
      "dom.iterable",
      "esnext"
    ],
    "allowJs": true,
    "skipLibCheck": true,
    "strict": false,
    "forceConsistentCasingInFileNames": true,
    "noEmit": true,
    "esModuleInterop": true,
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "jsx": "preserve"
  },
  "include": [
    "next-env.d.ts",
    "**/*.ts",
    "**/*.tsx"
  ],
  "exclude": [
    "node_modules"
  ]
}
thisismydesign commented 3 years ago

Apparently calling a page index.tsx will produce this error. Calling it home.tsx as in your example works. Perhaps a mention of this in the readme?

I got the index example from here: https://github.com/kelvin-mai/nest-next-example

kyle-mccarthy commented 3 years ago

Hi sorry for the delay in getting back to you. I actually haven't tried to use the nest cli along with this package before, in my example I just use nodemon for the dev command.

That being said, I don't think that the problem is actually related to naming the page index.tsx. In the basic example I have a page in /pages/views/blog/index.tsx and render it in the controller without it 404ing.

thisismydesign commented 3 years ago

I had pages/views/index.tsx and @Render('index'), you can reproduce it in the linked repo. Maybe I misunderstood how it's supposed to work, still, it was pretty confusing. Up to you how to handle this, feel free to just close.

birksy89 commented 3 years ago

I think I'm having a similar issue - I can't seem to get it to work with the Nest CLI

krunalshahcodes commented 3 years ago

@kyle-mccarthy I can confirm this. i have same issues @Render('index') throws an error if page is at pages/views/index.tsx but if it is at pages/views/blog/index.tsx it will work.