prisma-labs / graphql-framework-experiment

Code-First Type-Safe GraphQL Framework
https://nexusjs.org
MIT License
672 stars 66 forks source link

Environment Variables go missing when using npx nexus build #1167

Closed maaft closed 4 years ago

maaft commented 4 years ago
  1. build nexus-prisma app
  2. npx nexus build
  3. node .nexus/build/index.js
  4. use mutation or query

Nexus Report

{
  "node": "v14.4.0",
  "os": {
    "platform": "linux",
    "release": "5.3.0-61-generic"
  },
  "nexus": "^0.24.2",
  "plugins": [
    "nexus-plugin-shield",
    "nexus-plugin-prisma"
  ],
  "otherDependencies": {
    "@graphql-codegen/cli": "1.15.3",
    "@graphql-codegen/fragment-matcher": "1.15.3",
    "@graphql-codegen/introspection": "1.15.3",
    "@graphql-codegen/typescript": "1.15.3",
    "@graphql-codegen/typescript-document-nodes": "1.15.3",
    "@graphql-codegen/typescript-graphql-files-modules": "1.15.3",
    "@graphql-codegen/typescript-operations": "1.15.3",
    "@graphql-codegen/typescript-react-apollo": "1.15.3",
    "@types/bcryptjs": "^2.4.2",
    "@types/jsonwebtoken": "^8.5.0",
    "@types/node-cache": "^4.2.5",
    "apollo-server": "^2.15.0",
    "bcryptjs": "^2.4.3",
    "handy-redis": "^1.8.3",
    "jsonwebtoken": "^8.5.1",
    "minimatch": "^3.0.4",
    "nexus-prisma": "^0.15.0",
    "node-cache": "^5.1.1",
    "typescript": "^3.9.5"
  },
  "devDependencies": {},
  "hasAppModule": true,
  "packageManager": "npm",
  "errorsWhileGatheringReport": {
    "gettingLayout": null,
    "gettingPluginManifests": null
  }
}

Screenshot

image

Description

Somehow the environment variables are missing inside the built app.

npx nexus dev works, by the way!

maaft commented 4 years ago

Okay, I found the solution and I think at this point it's not a bug but rather a feature. The documentation should of course explain this briefly.

For future reference: For running your server in production (nexus build), you need to set all environment variables in the shell where you run your index.js:

export DATABASE_URL="...."
node index.js

Why is this a feature and not a bug?

This actually makes deployment more easy when you have to use e.g. different databases (or access credentials) in different environments.