Skip to content

Commit 432af39

Browse files
nestjs gide updated to esm (#7360)
1 parent 6bf7a40 commit 432af39

File tree

1 file changed

+24
-17
lines changed

1 file changed

+24
-17
lines changed

content/800-guides/430-nestjs.mdx

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,15 @@ cd nestjs-prisma
4242

4343
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_.
4444

45+
In `package.json`, add the `type` field set to `"module"`:
46+
47+
```json file=package.json
48+
{
49+
// add-next-line
50+
"type": "module"
51+
}
52+
```
53+
4554
## 2. Set up Prisma
4655

4756
### 2.1. Install Prisma and dependencies
@@ -73,16 +82,14 @@ This creates a new `prisma` directory with the following contents:
7382
- `prisma.config.ts`: A configuration file for your projects
7483
- `.env`: A [dotenv](https://github.com/motdotla/dotenv) file, typically used to store your database credentials in a group of environment variables
7584

76-
### 2.3. Set the generator output path and update the module format
85+
### 2.3. Set the generator output path
7786

78-
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`:
87+
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:
7988

8089
```prisma file=prisma/schema.prisma
8190
generator client {
8291
provider = "prisma-client"
8392
output = "../src/generated/prisma"
84-
// add-next-line
85-
moduleFormat = "cjs"
8693
}
8794
```
8895

@@ -169,7 +176,7 @@ Inside the `src` directory, create a new file called `prisma.service.ts` and add
169176

170177
```typescript file=src/prisma.service.ts
171178
import { Injectable } from '@nestjs/common';
172-
import { PrismaClient } from './generated/prisma/client';
179+
import { PrismaClient } from './generated/prisma/client.js';
173180
import { PrismaPg } from '@prisma/adapter-pg';
174181

175182
@Injectable()
@@ -193,8 +200,8 @@ Still inside the `src` directory, create a new file called `user.service.ts` and
193200

194201
```typescript file=src/user.service.ts
195202
import { Injectable } from '@nestjs/common';
196-
import { PrismaService } from './prisma.service';
197-
import { User, Prisma } from './generated/prisma/client';
203+
import { PrismaService } from './prisma.service.js';
204+
import { User, Prisma } from './generated/prisma/client.js';
198205

199206
@Injectable()
200207
export class UserService {
@@ -261,8 +268,8 @@ Still inside the `src` directory, create a new file called `post.service.ts` and
261268
```typescript file=src/post.service.ts
262269

263270
import { Injectable } from '@nestjs/common';
264-
import { PrismaService } from './prisma.service';
265-
import { Post, Prisma } from './generated/prisma/client';
271+
import { PrismaService } from './prisma.service.js';
272+
import { Post, Prisma } from './generated/prisma/client.js';
266273

267274
@Injectable()
268275
export class PostService {
@@ -338,10 +345,10 @@ import {
338345
Put,
339346
Delete,
340347
} from '@nestjs/common';
341-
import { UserService } from './user.service';
342-
import { PostService } from './post.service';
343-
import { User as UserModel } from './generated/prisma/client';
344-
import { Post as PostModel } from './generated/prisma/client';
348+
import { UserService } from './user.service.js';
349+
import { PostService } from './post.service.js';
350+
import { User as UserModel } from './generated/prisma/client.js';
351+
import { Post as PostModel } from './generated/prisma/client.js';
345352

346353
@Controller()
347354
export class AppController {
@@ -454,11 +461,11 @@ Update `src/app.module.ts` to register all services:
454461
import { Module } from '@nestjs/common';
455462
import { AppController } from './app.controller';
456463
import { ConfigModule } from '@nestjs/config';
457-
import { AppService } from './app.service';
464+
import { AppService } from './app.service.js';
458465
//add-start
459-
import { PrismaService } from './prisma.service';
460-
import { UserService } from './user.service';
461-
import { PostService } from './post.service';
466+
import { PrismaService } from './prisma.service.js';
467+
import { UserService } from './user.service.js';
468+
import { PostService } from './post.service.js';
462469
//add-end
463470

464471
@Module({

0 commit comments

Comments
 (0)