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

nexus-prisma types undefined when deploying to heroku #108

Closed
chrishoermann opened this issue Aug 8, 2021 · 22 comments · Fixed by #219
Closed

nexus-prisma types undefined when deploying to heroku #108

chrishoermann opened this issue Aug 8, 2021 · 22 comments · Fixed by #219
Labels
needs/discussion Something needs deciding, new info changes issue scope/spec, unforeseen challenges, etc. type/bug Something is not working the way it should

Comments

@chrishoermann
Copy link

When deploying to heroku the app crashes with the error seen in the screenshot.
local build works without any problems.

Screenshot

Heroku-deployment-not-working

Description

parts of my package.json file:

"scripts": {
    "start": "node .build/api/app.js",
    "postinstall": "prisma generate",
    "build": "tsc",
},
"dependencies": {
    "@prisma/client": "2.27.0",
    "apollo-server": "^2.25.2",
    "aws-sdk": "^2.939.0",
    "bcrypt": "^5.0.1",
    "cuid": "^2.1.8",
    "graphql": "^15.5.1",
    "graphql-middleware": "^6.0.10",
    "graphql-shield": "^7.5.0",
    "jsonwebtoken": "^8.5.1",
    "nexus": "^1.1.0",
    "nexus-prisma": "^0.30.0"
  },
 "devDependencies": {
    "typescript": "^4.3.5",
  },
@chrishoermann chrishoermann added the type/bug Something is not working the way it should label Aug 8, 2021
@chrishoermann chrishoermann changed the title nexus-prisma undefined when deploying on heroku nexus-prisma types undefined when deploying to heroku Aug 8, 2021
@P4sca1
Copy link

P4sca1 commented Aug 20, 2021

This might be because the prisma client and nexus were not successfully built, because of #107

@misha-erm
Copy link

Facing the same issue.
On build step at Heroku I can see that prisma was successfully generated.

Attaching my build log and application log

build log

-----> Building on the Heroku-20 stack
-----> Using buildpack: heroku/nodejs
-----> Node.js app detected
       
-----> Creating runtime environment
       
       NPM_CONFIG_LOGLEVEL=error
       USE_YARN_CACHE=true
       NODE_VERBOSE=false
       NODE_ENV=production
       NODE_MODULES_CACHE=true
       
-----> Installing binaries
       engines.node (package.json):  14.x
       engines.npm (package.json):   unspecified (use default)
       engines.yarn (package.json):  unspecified (use default)
       
       Resolving node version 14.x...
       Downloading and installing node 14.17.5...
       Using default npm version: 6.14.14
       Resolving yarn version 1.22.x...
       Downloading and installing yarn (1.22.11)
       Installed yarn 1.22.11
       
-----> Restoring cache
       - yarn cache
       
-----> Installing dependencies
       Installing node modules (yarn.lock)
       yarn install v1.22.11
       [1/4] Resolving packages...
       [2/4] Fetching packages...
       info fsevents@2.3.2: The platform "linux" is incompatible with this module.
       info "fsevents@2.3.2" is an optional dependency and failed compatibility check. Excluding it from installation.
       [3/4] Linking dependencies...
       warning " > nexus-prisma@0.30.0" has incorrect peer dependency "@prisma/client@2.17.x || 2.18.x || 2.19.x || 2.20.x || 2.21.x || 2.22.x || 2.23.x || 2.24.x || 2.25.x || 2.26.x || 2.27.x".
       warning "xo > eslint-import-resolver-webpack@0.13.1" has unmet peer dependency "webpack@>=1.11.0".
       [4/4] Building fresh packages...
       $ husky install
       fatal: not a git repository (or any parent up to mount point /)
       Stopping at filesystem boundary (GIT_DISCOVERY_ACROSS_FILESYSTEM not set).
       Done in 20.66s.
       
-----> Build
       Running build (yarn)
       yarn run v1.22.11
       $ yarn prisma:generate && NEXUS_SHOULD_GENERATE_ARTIFACTS=true node --loader ts-node/esm/transpile-only ./src/schema.ts && tsc
       $ prisma generate
       Prisma schema loaded from prisma/schema.prisma
       You can now start using Nexus Prisma in your code. Reference: https://pris.ly/d/nexus-prisma
       
       ✔ Generated Prisma Client (2.29.1) to ./node_modules/@prisma/client in 268ms
       
       ✔ Generated Nexus Prisma to ./node_modules/nexus-prisma/dist/runtime in 324ms
       You can now start using Prisma Client in your code. Reference: https://pris.ly/d/client
       ```
       import { PrismaClient } from '@prisma/client'
       const prisma = new PrismaClient()
       ```
(node:1651) ExperimentalWarning: --experimental-loader is an experimental feature. This feature could change at any time
(Use `node --trace-warnings ...` to show where the warning was created)
WARNING: Peer dependency validation check failed: nexus-prisma@0.30.0 does not officially support @prisma/client@2.29.1. The officially supported range is: `2.17.x || 2.18.x || 2.19.x || 2.20.x || 2.21.x || 2.22.x || 2.23.x || 2.24.x || 2.25.x || 2.26.x || 2.27.x`. This could lead to undefined behaviors and bugs.
       Done in 11.93s.
       
-----> Pruning devDependencies
       yarn install v1.22.11
       [1/4] Resolving packages...
       [2/4] Fetching packages...
       info fsevents@2.3.2: The platform "linux" is incompatible with this module.
       info "fsevents@2.3.2" is an optional dependency and failed compatibility check. Excluding it from installation.
       [3/4] Linking dependencies...
       warning " > nexus-prisma@0.30.0" has incorrect peer dependency "@prisma/client@2.17.x || 2.18.x || 2.19.x || 2.20.x || 2.21.x || 2.22.x || 2.23.x || 2.24.x || 2.25.x || 2.26.x || 2.27.x".
       warning "xo > eslint-import-resolver-webpack@0.13.1" has unmet peer dependency "webpack@>=1.11.0".
       [4/4] Building fresh packages...
       warning Ignored scripts due to flag.
       Done in 5.55s.
       
-----> Caching build
       - yarn cache
       
-----> Build succeeded!
 !     Unmet dependencies don't fail yarn install but may cause runtime issues
       https://github.com/npm/npm/issues/7494
-----> Discovering process types
       Procfile declares types -> release, web
-----> Compressing...
       Done: 104.3M
-----> Launching...
 !     Release command declared: this new release will not be available until the command succeeds.
       Released v9
       https://cheapoil.herokuapp.com/ deployed to Heroku

application log

2021-08-21T16:16:22.322915+00:00 heroku[web.1]: State changed from crashed to starting
2021-08-21T16:16:27.847214+00:00 heroku[web.1]: Starting process with command `node dist/server.js`
2021-08-21T16:16:30.540109+00:00 app[web.1]: WARNING: Peer dependency validation check failed: nexus-prisma@0.30.0 does not officially support @prisma/client@2.29.1. The officially supported range is: `2.17.x || 2.18.x || 2.19.x || 2.20.x || 2.21.x || 2.22.x || 2.23.x || 2.24.x || 2.25.x || 2.26.x || 2.27.x`. This could lead to undefined behaviors and bugs.
2021-08-21T16:16:30.559144+00:00 app[web.1]: file:///app/dist/schema.js:19
2021-08-21T16:16:30.559146+00:00 app[web.1]:     name: FuelStation.$name,
2021-08-21T16:16:30.559146+00:00 app[web.1]:                       ^
2021-08-21T16:16:30.559146+00:00 app[web.1]: 
2021-08-21T16:16:30.559147+00:00 app[web.1]: TypeError: Cannot read property '$name' of undefined
2021-08-21T16:16:30.559147+00:00 app[web.1]:     at file:///app/dist/schema.js:19:23
2021-08-21T16:16:30.559148+00:00 app[web.1]:     at ModuleJob.run (internal/modules/esm/module_job.js:170:25)
2021-08-21T16:16:30.559150+00:00 app[web.1]:     at async Loader.import (internal/modules/esm/loader.js:178:24)
2021-08-21T16:16:30.559150+00:00 app[web.1]:     at async Object.loadESM (internal/process/esm_loader.js:68:5)
2021-08-21T16:16:30.599753+00:00 heroku[web.1]: Process exited with status 1
2021-08-21T16:16:30.727202+00:00 heroku[web.1]: State changed from starting to crashed

@misha-erm
Copy link

As a workaround installing all dependencies in heroku and building again helped me

Procfile:

web: NODE_ENV=development yarn && yarn build && yarn start

@jasonkuhrt
Copy link
Contributor

@MikeYermolayev Indeed the generator is running, yet somehow your runtime does not have the result of that generated code.

Is there a way you can share what code is actually running? Not sure how helpful that info will be though.

After the build step, it seems that Heroku is not pulling in the modified version of node_modules.

Maybe there is a caching issue of some sort.

However, wonder why @prisma/client is working then...

I would be open to allowing users to customize where the nexus-prisma generated runtime is emitted to. However, that would add complexity for users and I want to only do that once we understand there is no other option.

@jasonkuhrt jasonkuhrt added the needs/discussion Something needs deciding, new info changes issue scope/spec, unforeseen challenges, etc. label Aug 24, 2021
@maks112v
Copy link

Getting the same error. thought I was doing something wrong first time using nexus. anything I can provide to help?

@jasonkuhrt
Copy link
Contributor

jasonkuhrt commented Aug 30, 2021

@maks112v If you can share a repro-repo with that would help. More minimal the better. I can then setup my own heroku app to run it and see the repro.

@maks112v
Copy link

maks112v commented Aug 30, 2021

https://www.dropbox.com/s/kh982dy2xrcgat0/api.zip?dl=0
It is a very basic api I just started it yesterday

@misha-erm
Copy link

The issue seems connected with https://devcenter.heroku.com/articles/troubleshooting-node-deploys#missing-modules
Setting YARN_PRODUCTION=false fixed it for me.

I doubt any actions are expected from nexus-prisma team except maybe adding to to troubleshoot section

@jasonkuhrt
Copy link
Contributor

@MikeYermolayev did you install nexus-prisma to dev dependencies?

@jasonkuhrt
Copy link
Contributor

Thanks @maks112v will try to look soon but might be a few weeks.

@misha-erm
Copy link

No. It's installed as dependency.

"dependencies": {
    "@prisma/client": "2.30.3",
    "date-fns": "2.23.0",
    "dotenv": "10.0.0",
    "envalid": "7.2.1",
    "fastify": "3.20.2",
    "fastify-plugin": "3.0.0",
    "graphql": "15.5.2",
    "mercurius": "8.1.3",
    "nexus": "1.1.0",
    "nexus-prisma": "0.31.0",
    "pino-colada": "2.1.0"
  },
  "devDependencies": {
    "@types/jest": "27.0.1",
    "@types/node": "16.7.10",
    "@typescript-eslint/eslint-plugin": "4.30.0",
    "@typescript-eslint/parser": "4.30.0",
    "eslint": "7.32.0",
    "eslint-config-prettier": "8.3.0",
    "eslint-plugin-jest": "24.4.0",
    "eslint-plugin-node": "11.1.0",
    "eslint-plugin-promise": "5.1.0",
    "eslint-plugin-unicorn": "35.0.0",
    "husky": "7.0.2",
    "jest": "27.1.0",
    "lint-staged": "11.1.2",
    "nodemon": "2.0.12",
    "prettier": "2.3.2",
    "prisma": "2.30.3",
    "ts-jest": "27.0.5",
    "ts-node": "10.2.1",
    "typescript": "4.4.2"
  },

no idea why it gets pruned

@trey-m
Copy link

trey-m commented Sep 19, 2021

Running into a potentially similar issue as well: Type error: Module '"nexus-prisma"' has no exported member 'Model' within the github action runner. I know this is still in early stages of development but wanted to report it.

@jasonkuhrt
Copy link
Contributor

@trey-m do you have a repro for that I can look at?

@P4sca1
Copy link

P4sca1 commented Sep 20, 2021

Running into a potentially similar issue as well: Type error: Module '"nexus-prisma"' has no exported member 'Model' within the github action runner. I know this is still in early stages of development but wanted to report it.

Manually run prisma generate after installing your dependencies as a workaround.

@trey-m
Copy link

trey-m commented Sep 20, 2021

Running into a potentially similar issue as well: Type error: Module '"nexus-prisma"' has no exported member 'Model' within the github action runner. I know this is still in early stages of development but wanted to report it.

Manually run prisma generate after installing your dependencies as a workaround.

I currently have a postinstall script that runs prisma generate.

image

Update: This issue was on my end. Sorry for raising a false flag.

@JulianKarhof
Copy link

Seeing the same issue during a docker build where removing the part that prunes dev-dependencies fixes the issue. nexus-prisma is installed as a normal dependency though so i don't see how that could happen.

FROM mhart/alpine-node:14 as build
WORKDIR /app
ENV CI=true

RUN apk update && apk upgrade
RUN apk --no-cache add git make gcc g++ python3 openssl

# copy project
COPY . .

# Remove large unused packages
RUN rm -rf packages/client

# Install all dependencies
RUN yarn install --frozen-lockfile
RUN yarn lerna run build --scope=@app/server --include-dependencies

# Remove dev-dependencies
RUN yarn install --production --ignore-scripts --prefer-offline # Commenting out this line fixes the issue

leads to

/app/packages/server/dist/api/user/user.type.js:13
    name: nexus_prisma_1.User.$name,
TypeError: Cannot read property '$name' of undefined

@MitchellRomney
Copy link

Would just like to follow up on this issue, was having the same production deploy error as above, using Dokku:
TypeError: Cannot read property '$name' of undefined

Was able to fix it by setting YARN_PRODUCTION=false as mentioned, although long term would like to not have to use this flag - any updates on this weird interaction?

@trey-m
Copy link

trey-m commented Oct 31, 2021

Would just like to follow up on this issue, was having the same production deploy error as above, using Dokku: TypeError: Cannot read property '$name' of undefined

Was able to fix it by setting YARN_PRODUCTION=false as mentioned, although long term would like to not have to use this flag - any updates on this weird interaction?

Did you ensure that you run prisma generate before any type checking?

@zaniluca
Copy link

zaniluca commented Feb 1, 2022

I'm facing the same problem too when deploying to Heroku, I've tried changing the generator's output but it seems like nexus-prisma doesn't generate the types:
img
As you can see the generated folder isn't there only when using build command, this is my prisma file:

generator client {
  provider = "prisma-client-js"
}

generator nexusPrisma {
  provider = "nexus-prisma"
  output   = "../src/generated/nexus-prisma"
}

datasource db {
  provider = "postgresql"
  url      = env("DATABASE_URL")
}
...

@AhmedElywa
Copy link
Contributor

I'm facing the same problem too when deploying to Heroku, I've tried changing the generator's output but it seems like nexus-prisma doesn't generate the types: img As you can see the generated folder isn't there only when using build command, this is my prisma file:

generator client {
  provider = "prisma-client-js"
}

generator nexusPrisma {
  provider = "nexus-prisma"
  output   = "../src/generated/nexus-prisma"
}

datasource db {
  provider = "postgresql"
  url      = env("DATABASE_URL")
}
...

yes because tsc command doesn't copy the .js file by default you need to include

{
  "compilerOptions": {
    //...
    // add this option to your tsconfig.ts file will fix the issue
    "allowJs": true
  },
}

@AhmedElywa
Copy link
Contributor

The issue comes from using yarn when Heroku starting Pruning devDependencies yarn rebuild fresh packages this means that the generated code by the prisma generate command will delete.

image

We have two solutions:

1 - Using npm because it's using another strategy for Pruning devDependencies and delete only devDependencies and not rebuild all packages

image

2- Using a custom output path you will need to create a configuration file in one of the following locations

→ nexus-prisma.ts
→ nexusPrisma.ts
→ nexus_prisma.ts
→ prisma/nexus-prisma.ts
→ prisma/nexusPrisma.ts
→ prisma/nexus_prisma.ts

Then add the following code:

settings({
  output: './generated/nexus-prisma'
})

Because the output will be in .js you will need to include the .js files into your tsconfig.ts file by adding this prop.

{
  "compilerOptions": {
    ...
    "allowJs": true
  },
}

@rostislav-simonik-nexus-prisma-admin
Copy link
Collaborator

🎉 This issue has been resolved in version 1.0.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs/discussion Something needs deciding, new info changes issue scope/spec, unforeseen challenges, etc. type/bug Something is not working the way it should
Projects
None yet