diff --git a/content/800-guides/430-nestjs.mdx b/content/800-guides/430-nestjs.mdx index 11cf0dc431..c5f083fa60 100644 --- a/content/800-guides/430-nestjs.mdx +++ b/content/800-guides/430-nestjs.mdx @@ -42,6 +42,15 @@ cd nestjs-prisma You can run `npm start` to start your application at `http://localhost:3000/`. Over the course of this guide, you'll add routes to store and retrieve data about _users_ and _posts_. +In `package.json`, add the `type` field set to `"module"`: + +```json file=package.json +{ + // add-next-line + "type": "module" +} +``` + ## 2. Set up Prisma ### 2.1. Install Prisma and dependencies @@ -73,16 +82,14 @@ This creates a new `prisma` directory with the following contents: - `prisma.config.ts`: A configuration file for your projects - `.env`: A [dotenv](https://github.com/motdotla/dotenv) file, typically used to store your database credentials in a group of environment variables -### 2.3. Set the generator output path and update the module format +### 2.3. Set the generator output path -Specify your output `path` for the generated Prisma client by either passing `--output ../src/generated/prisma` during `prisma init` or directly in your Prisma schema. Also, update the `moduleFormat` to `cjs`: +Specify your output `path` for the generated Prisma client by either passing `--output ../src/generated/prisma` during `prisma init` or directly in your Prisma schema: ```prisma file=prisma/schema.prisma generator client { provider = "prisma-client" output = "../src/generated/prisma" - // add-next-line - moduleFormat = "cjs" } ``` @@ -169,7 +176,7 @@ Inside the `src` directory, create a new file called `prisma.service.ts` and add ```typescript file=src/prisma.service.ts import { Injectable } from '@nestjs/common'; -import { PrismaClient } from './generated/prisma/client'; +import { PrismaClient } from './generated/prisma/client.js'; import { PrismaPg } from '@prisma/adapter-pg'; @Injectable() @@ -193,8 +200,8 @@ Still inside the `src` directory, create a new file called `user.service.ts` and ```typescript file=src/user.service.ts import { Injectable } from '@nestjs/common'; -import { PrismaService } from './prisma.service'; -import { User, Prisma } from './generated/prisma/client'; +import { PrismaService } from './prisma.service.js'; +import { User, Prisma } from './generated/prisma/client.js'; @Injectable() export class UserService { @@ -261,8 +268,8 @@ Still inside the `src` directory, create a new file called `post.service.ts` and ```typescript file=src/post.service.ts import { Injectable } from '@nestjs/common'; -import { PrismaService } from './prisma.service'; -import { Post, Prisma } from './generated/prisma/client'; +import { PrismaService } from './prisma.service.js'; +import { Post, Prisma } from './generated/prisma/client.js'; @Injectable() export class PostService { @@ -338,10 +345,10 @@ import { Put, Delete, } from '@nestjs/common'; -import { UserService } from './user.service'; -import { PostService } from './post.service'; -import { User as UserModel } from './generated/prisma/client'; -import { Post as PostModel } from './generated/prisma/client'; +import { UserService } from './user.service.js'; +import { PostService } from './post.service.js'; +import { User as UserModel } from './generated/prisma/client.js'; +import { Post as PostModel } from './generated/prisma/client.js'; @Controller() export class AppController { @@ -454,11 +461,11 @@ Update `src/app.module.ts` to register all services: import { Module } from '@nestjs/common'; import { AppController } from './app.controller'; import { ConfigModule } from '@nestjs/config'; -import { AppService } from './app.service'; +import { AppService } from './app.service.js'; //add-start -import { PrismaService } from './prisma.service'; -import { UserService } from './user.service'; -import { PostService } from './post.service'; +import { PrismaService } from './prisma.service.js'; +import { UserService } from './user.service.js'; +import { PostService } from './post.service.js'; //add-end @Module({