nest-next icon indicating copy to clipboard operation
nest-next copied to clipboard

Usage with Nest CLI

Open thisismydesign opened this issue 3 years ago • 5 comments

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

  • next.js: 9.4.0
  • nest: 7.5.1
  • nest-next: 9.4.0

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 avatar Apr 08 '21 20:04 thisismydesign

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

thisismydesign avatar Apr 09 '21 12:04 thisismydesign

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.

kyle-mccarthy avatar Apr 10 '21 19:04 kyle-mccarthy

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.

thisismydesign avatar Apr 11 '21 00:04 thisismydesign

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

birksy89 avatar May 02 '21 14:05 birksy89

@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.

krunalcodes avatar May 20 '21 18:05 krunalcodes