Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prisma client fails build #73

Closed
jeremygottfried opened this issue Mar 8, 2021 · 7 comments
Closed

Prisma client fails build #73

jeremygottfried opened this issue Mar 8, 2021 · 7 comments
Labels
bug Something isn't working

Comments

@jeremygottfried
Copy link

Build fails for projects using prisma client.

Type error: Module '"../../../node_modules/@prisma/client"' has no exported member 'MyModel'.

import { MyModel } from '@prisma/client';

Build failed:
NowBuildError: Command "yarn run build" exited with 1
at ChildProcess. (/Users/jeremygottfried/Development/sweepstakes-app/sweepstakes-next-app/node_modules/@vercel/build-utils/dist/index.js:29311:20)
at ChildProcess.emit (events.js:310:20)
at ChildProcess.EventEmitter.emit (domain.js:482:12)
at maybeClose (internal/child_process.js:1021:16)
at Process.ChildProcess._handle.onexit (internal/child_process.js:286:5) {
hideStackTrace: true,
code: 'BUILD_UTILS_SPAWN_1',
link: undefined,
action: undefined
}

@jeremygottfried jeremygottfried changed the title Prisma client prevents build Prisma client fails build Mar 8, 2021
@ofhouse
Copy link
Member

ofhouse commented Mar 9, 2021

Can you share more information about your project?

Seems more like a TypeScript error in the first place.
I tried out the official JavaScript example and the build looks fine to me.

However using the TypeScript example gives me a lot of TypeScript related errors.
Have you tried deploying it to Vercel, does it work there (Asking because we use a similar build process as Vercel under the hood)?

@jeremygottfried
Copy link
Author

Yes it's a typescript error.

Can you share more information about your project?

Seems more like a TypeScript error in the first place.
I tried out the official JavaScript example and the build looks fine to me.

However using the TypeScript example gives me a lot of TypeScript related errors.

Yeah I have deployed it to Vercel. I don't seem to have any typescript related issues there.

Have you tried deploying it to Vercel, does it work there (Asking because we use a similar build process as Vercel under the hood)?

Here's my tsconfig

{
  "compilerOptions": {
    "sourceMap": true,
    "outDir": "dist",
    "strict": true,
    "lib": [
      "esnext"
    ],
    "esModuleInterop": true,
    "target": "es5",
    "allowJs": true,
    "skipLibCheck": true,
    "forceConsistentCasingInFileNames": true,
    "noEmit": true,
    "module": "esnext",
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "jsx": "preserve"
  },
  "include": [
    "next-env.d.ts",
    "**/*.ts",
    "**/*.tsx"
  ],
  "exclude": [
    "node_modules"
  ]
}

tf-next version: 0.5.0
ts-node version: 9.1.1
typescript version: 4.1.3
prisma/cli version: 2.18.0
prisma/client version: 2.16.1
next version: 10.0.5

Here's next.config.js:

const withTM = require('next-transpile-modules')(['react-spring']); // pass the modules you would like to see transpiled
const path = require("path");

module.exports = withTM();

main.tf:

# main.tf

terraform {
  required_providers {
    aws = {
      source  = "hashicorp/aws"
      version = "~> 3.0"
    }
  }
}

# Main region where the resources should be created in
provider "aws" {
  region = "us-east-1"
}

module "tf_next" {
  source = "dealmore/next-js/aws"
}

output "cloudfront_domain_name" {
  value = module.tf_next.cloudfront_domain_name
}

@ofhouse
Copy link
Member

ofhouse commented Mar 18, 2021

Sorry for the radio silence here.
Saw a similar error with Blitz.js and Prisma today and it seems that tf-next has some problems with prisma when it runs it inside the temporary directory it creates for every build.

As a workaround you can run tf-next build --skipDownload which runs tf-next in the same directory instead of creating a temporary one.
This fixed the issue for me (note that tf-next makes some changes to your next.config.js then that should not commited) but will investigate further why the build fails in the temporary directory.

@jeremygottfried
Copy link
Author

Great thanks I'll try the workaround when I have a chance!

@ofhouse ofhouse added the bug Something isn't working label Mar 19, 2021
@ofhouse
Copy link
Member

ofhouse commented Mar 19, 2021

Okay, finally found the main issue.
Prisma uses the NOW_BUILDER environment variable to detect the build environment in Vercel builds.
https://github.com/prisma/prisma/blob/1d0045fe60dc1992173f3f5be84b24129f0d45a3/src/packages/cli/scripts/install.js#L10

Since our build environment is forked from the Vercel environment we also need to set this environment variable in order to get the workaround from Prisma correctly applied.
It could work to set the NOW_BUILDER='1' environment variable manually before running tf-next (not checked) but I prepare a general fix for this issue in #85.

@ofhouse
Copy link
Member

ofhouse commented Mar 20, 2021

Just released tf-next@0.6.0 which should fix the issue.
Upgrading tf-next in your package.json should be enough to make it work, no update of the Terraform module required.

@ofhouse
Copy link
Member

ofhouse commented Mar 23, 2021

Ok there was still a small error, which caused the types generation to take place in the wrong directory.
This was fixed in #87 and released in tf-next@0.6.1.
Closing this for now.

@ofhouse ofhouse closed this as completed Mar 23, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants