prisma / prisma

Next-generation ORM for Node.js & TypeScript | PostgreSQL, MySQL, MariaDB, SQL Server, SQLite, MongoDB and CockroachDB
https://www.prisma.io
Apache License 2.0
39.6k stars 1.54k forks source link

NestJs error compilation #1726

Closed JCLMAQ closed 4 years ago

JCLMAQ commented 4 years ago
  1. Prisma2 version (prisma2 -v): preview021
  2. Logs from Developer Tools Console, if any: I run prisma2 within a nestjs backend. When I start prisma2 studio with nestjs running, I get the following nestjs compliation error related to the auto created studio folder (within the prisma folder):
    
    > nest start --watch

11:55:38 - Starting compilation in watch mode...

prisma/Studio/-Wakanda-Desktop-NestJS-nestjs-prisma2-jcm-backend/runtime/browser.d.ts:5:41 - error TS2307: Cannot find module '@prisma/engine-core/dist/BrowserEngine'.

5 export { BrowserEngine as Engine } from '@prisma/engine-core/dist/BrowserEngine';


prisma/Studio/-Wakanda-Desktop-NestJS-nestjs-prisma2-jcm-backend/runtime/externalToInternalDmmf.d.ts:1:38 - error TS2307: Cannot find module '@prisma/generator-helper'.

1 import { DMMF as ExternalDMMF } from '@prisma/generator-helper';

prisma/Studio/-Wakanda-Desktop-NestJS-nestjs-prisma2-jcm-backend/runtime/getDMMF.d.ts:1:22 - error TS2307: Cannot find module '@prisma/generator-helper'.

1 import { DMMF } from '@prisma/generator-helper';


prisma/Studio/-Wakanda-Desktop-NestJS-nestjs-prisma2-jcm-backend/runtime/getDMMF.d.ts:2:32 - error TS2307: Cannot find module '@prisma/sdk'.

2 import { GetDMMFOptions } from '@prisma/sdk';

prisma/Studio/-Wakanda-Desktop-NestJS-nestjs-prisma2-jcm-backend/runtime/highlight/theme.d.ts:3:30 - error TS2503: Cannot find namespace 'chalk'. 3 export declare const orange: chalk.Chalk;

prisma/Studio/-Wakanda-Desktop-NestJS-nestjs-prisma2-jcm-backend/runtime/highlight/theme.d.ts:4:38 - error TS2503: Cannot find namespace 'chalk'.

4 export declare const darkBrightBlue: chalk.Chalk;

prisma/Studio/-Wakanda-Desktop-NestJS-nestjs-prisma2-jcm-backend/runtime/highlight/theme.d.ts:5:28 - error TS2503: Cannot find namespace 'chalk'. 5 export declare const blue: chalk.Chalk;

prisma/Studio/-Wakanda-Desktop-NestJS-nestjs-prisma2-jcm-backend/runtime/highlight/theme.d.ts:6:34 - error TS2503: Cannot find namespace 'chalk'.
6 export declare const brightBlue: chalk.Chalk;
Is there any way to avoid those errors ?

3. Does the issue persist even after updating to the latest `prisma2` alpha (`npm i -g prisma2@alpha`)?

4. Prisma2 schema (if relevant):
JCLMAQ commented 4 years ago

Error stay with preview022. Adding within package.json (devDependencies):

"@prisma/sdk": "^0.0.208",
    "@prisma/engine-core": "^2.0.110",
    "@prisma/generator-helper": "^0.0.40",
     "chalk": "^3.0.0",

avoid errors linked to @prisma unless the one related to "chalk".

sdnts commented 4 years ago

Hey @JCLMAQ, thanks for reporting this! Do you have a simple repo where I can see this as well?

I haven't used NestJS before, but I think autogenerated files should be excluded from compilation. Either way, an example repo would help me dig deeper!

JCLMAQ commented 4 years ago

There is an invitation for the repo I use: https://github.com/JCLMAQ/nestjs-prisma2-jcm/invitations I still have the error for 'Chalk', but for now NestJS don't stop anymore...

10:24:26 - File change detected. Starting incremental compilation...

prisma/Studio/-Wakanda-Desktop-NestJS-nestjs-prisma2-jcm-backend/runtime/highlight/theme.d.ts:1:8 - error TS1259: Module '"D:/Wakanda-Desktop/NestJS/nestjs-prisma2-jcm/backend/node_modules/chalk/index"' can only be default-imported using the 'esModuleInterop' flag

1 import chalk from 'chalk';
         ~~~~~

  node_modules/chalk/index.d.ts:411:1
    411 export = chalk;
        ~~~~~~~~~~~~~~~
    This module is declared with using 'export =', and can only be used with a default import when using the 'esModuleInterop' flag.

10:24:29 - Found 1 error. Watching for file changes.
[Nest] 15000   - 28/02/2020 à 10:24:29   [NestFactory] Starting Nest application...
[Nest] 15000   - 28/02/2020 à 10:24:29   [InstanceLoader] AppModule dependencies initialized +52ms
[Nest] 15000   - 28/02/2020 à 10:24:29   [Insta...
sdnts commented 4 years ago

Hey, I'm going to transfer this to the prisma2 repo, since this does not seem specific to Studio, but rather something with the prisma2 CLI's build. @pantharshit00 can then take a look. Could you share your repo with him as well? (Or perhaps make it public?) He also pointed me to a NestJS template a community member made that you might find useful to compare to: https://github.com/fivethree-team/nestjs-prisma-starter

Might I also suggest turning on esModuleInterop in your tsconfig as the error states and see if that helps?

JCLMAQ commented 4 years ago

Thanks for the reply. To start with prisma2 and Nestjs in fact I did use the NestJS template you point out . @pantharshit00 an invitation for the repo (still private for know) https://github.com/JCLMAQ/nestjs-prisma2-jcm/invitations

JCLMAQ commented 4 years ago

Adding "esModuleInterop = true" in nestjs config.ts solve the issue. Thanks. I should read error state more often ...

pantharshit00 commented 4 years ago

@JCLMAQ Sorry for the late reply here, but can this be closed now as this is resolved? Can you please confirm?

JCLMAQ commented 4 years ago

Yes. Thank you.