Module “@prisma/client”中没有导出成员”User”。

huangapple go评论75阅读模式
英文:

TS2305: Module '"@prisma/client"' has no exported member 'User'

问题

I am try to set up a Gitlab CI for a nestjs project that uses prisma. When I run the pipeline, I get this error:
enter image description here

My .gitlab-ci.yml:

image: node:latest

stages:
  - build

build:
  stage: build
  before_script:
    - corepack enable
    - corepack prepare pnpm@latest-8 --activate
    - pnpm config set store-dir .pnpm-store
  script:
    - pnpm install
    - npx prisma generate
    - pnpm run build
  cache:
    key:
      files:
        - pnpm-lock.yaml
    paths:
      - .pnpm-store
  artifacts:
    paths:
      - dist

user.models.ts:

import { User } from "@prisma/client"; # Line that is causing the build to fail in the CI
import { IsEmail, IsInt, IsNotEmpty, IsString } from "class-validator";

class UserModel implements User {
	@IsNotEmpty()
    @IsInt()
	id: number;

    @IsNotEmpty()
	@IsString()
    @IsEmail()
	email: string;

    @IsNotEmpty()
	@IsString()
	password: string;
}

Running pnpm run build locally works fine.

With the following scripts I have manually looked at the output generated by prisma, and I can see that User is being exported as a type from index.d.ts:

- cd ./node_modules/.prisma/client
- cat index.d.ts
- cd ../../..
英文:

I am try to set up a Gitlab CI for a nestjs project that uses prisma. When I run the pipeline, I get this error:
enter image description here

My .gitlab-ci.yml:

image: node:latest

stages:
  - build

build:
  stage: build
  before_script:
    - corepack enable
    - corepack prepare pnpm@latest-8 --activate
    - pnpm config set store-dir .pnpm-store
  script:
    - pnpm install
    - npx prisma generate
    - pnpm run build
  cache:
    key:
      files:
        - pnpm-lock.yaml
    paths:
      - .pnpm-store
  artifacts:
    paths:
      - dist

user.models.ts:

import { User } from "@prisma/client"; # Line that is causing the build to fail in the CI
import { IsEmail, IsInt, IsNotEmpty, IsString } from "class-validator";

class UserModel implements User {
	@IsNotEmpty()
    @IsInt()
	id: number;

    @IsNotEmpty()
	@IsString()
    @IsEmail()
	email: string;

    @IsNotEmpty()
	@IsString()
	password: string;
}

Running pnpm run build locally works fine.

With the following scripts I have manually looked at the output generated by prisma, and I can see that User is being exported as a type from index.d.ts.

- cd ./node_modules/.prisma/client
- cat index.d.ts
- cd ../../..

答案1

得分: 0

请确保您在 prisma.schema 文件中为 types to stored 设置了正确的输出值,理想情况下,它将是您的 node_modules 目录下的路径:

generator client {
  ...
  output = "../../node_modules/.prisma/client"
  ...
}
英文:

For anybody else with this issue, make sure you have set output value a it is below in your prisma.schema file for types to stored, this ideally will be your node_modules directory

generator client {
  ...
  output = "../../node_modules/.prisma/client"
  ...
}

答案2

得分: -4

I needed to use import type { User } instead of import { User }.

英文:

I needed to use import type { User } instead of import { User }.

huangapple
  • 本文由 发表于 2023年4月13日 22:26:07
  • 转载请务必保留本文链接:https://go.coder-hub.com/76006609.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定