a month ago
[Nest] 38 - 09/30/2025, 3:12:40 PM ERROR [ExceptionHandler] Error: JWT_SECRET environment variable is not defined
at new JwtStrategy (/app/src/auth/jwt.strategy.ts:12:19)
at Injector.instantiateClass (/app/node_modules/@nestjs/core/injector/injector.js:413:19)
at callback (/app/node_modules/@nestjs/core/injector/injector.js:70:45)
at process.processTicksAndRejections (node:internal/process/task_queues:105:5)
at async Injector.resolveConstructorParams (/app/node_modules/@nestjs/core/injector/injector.js:168:24)
at async Injector.loadInstance (/app/node_modules/@nestjs/core/injector/injector.js:75:13)
at async Injector.loadProvider (/app/node_modules/@nestjs/core/injector/injector.js:103:9)
at async /app/node_modules/@nestjs/core/injector/instance-loader.js:56:13
at async Promise.all (index 4)
at async InstanceLoader.createInstancesOfProviders (/app/node_modules/@nestjs/core/injector/instance-loader.js:55:9)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
yarn run v1.22.22
$ nest start
[dotenv@17.2.3] injecting env (0) from .env -- tip:
suppress all logs with { quiet: true }
[Nest] 38 - 09/30/2025, 3:12:45 PM LOG [NestFactory] Starting Nest application...
[Nest] 38 - 09/30/2025, 3:12:45 PM ERROR [ExceptionHandler] Error: JWT_SECRET environment variable is not defined
at new JwtStrategy (/app/src/auth/jwt.strategy.ts:12:19)
at Injector.instantiateClass (/app/node_modules/@nestjs/core/injector/injector.js:413:19)
at callback (/app/node_modules/@nestjs/core/injector/injector.js:70:45)
at process.processTicksAndRejections (node:internal/process/task_queues:105:5)
at async Injector.resolveConstructorParams (/app/node_modules/@nestjs/core/injector/injector.js:168:24)
at async Injector.loadInstance (/app/node_modules/@nestjs/core/injector/injector.js:75:13)
at async Injector.loadProvider (/app/node_modules/@nestjs/core/injector/injector.js:103:9)
at async /app/node_modules/@nestjs/core/injector/instance-loader.js:56:13
at async Promise.all (index 4)
at async InstanceLoader.createInstancesOfProviders (/app/node_modules/@nestjs/core/injector/instance-loader.js:55:9)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
yarn run v1.22.22
$ nest start
[dotenv@17.2.3] injecting env (0) from .env -- tip:
add access controls to secrets: https://dotenvx.com/ops
[Nest] 38 - 09/30/2025, 3:12:51 PM LOG [NestFactory] Starting Nest application...
[Nest] 38 - 09/30/2025, 3:12:51 PM ERROR [ExceptionHandler] Error: JWT_SECRET environment variable is not defined
at new JwtStrategy (/app/src/auth/jwt.strategy.ts:12:19)
at Injector.instantiateClass (/app/node_modules/@nestjs/core/injector/injector.js:413:19)
at callback (/app/node_modules/@nestjs/core/injector/injector.js:70:45)
at process.processTicksAndRejections (node:internal/process/task_queues:105:5)
at async Injector.resolveConstructorParams (/app/node_modules/@nestjs/core/injector/injector.js:168:24)
at async Injector.loadInstance (/app/node_modules/@nestjs/core/injector/injector.js:75:13)
at async Injector.loadProvider (/app/node_modules/@nestjs/core/injector/injector.js:103:9)
at async /app/node_modules/@nestjs/core/injector/instance-loader.js:56:13
at async Promise.all (index 4)
at async InstanceLoader.createInstancesOfProviders (/app/node_modules/@nestjs/core/injector/instance-loader.js:55:9)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
yarn run v1.22.22
$ nest start
[dotenv@17.2.3] injecting env (0) from .env -- tip: 
35 Replies
a month ago
Hey there! We've found the following might help you get unblocked faster:
If you find the answer from one of these, please let us know by solving the thread!
a month ago
This error shows that your app is expecting a JWT_SECRET environment variable but is not receiving one, most likely case is that you haven't set that variable within your service.
Inside of your service variables you'll want to specify a JWT_SECRET variable, this variable is often used in apps to secure JWT tokens. Just set it to whatever value just make sure the value you use is super random. You might want to use a random token generator online to generate a JWT token for this purpose
dev
This error shows that your app is expecting a JWT_SECRET environment variable but is not receiving one, most likely case is that you haven't set that variable within your service.Inside of your service variables you'll want to specify a JWT_SECRET variable, this variable is often used in apps to secure JWT tokens. Just set it to whatever value just make sure the value you use is super random. You might want to use a random token generator online to generate a JWT token for this purpose
a month ago
I have set the jwt token already and i have already set jwt secret in the share environment
a month ago
When you say "share environment", do you mean shared variables? Also, have you deployed the changes after setting your JWT token (silly question but people often forget to do this lol)
dev
When you say "share environment", do you mean shared variables? Also, have you deployed the changes after setting your JWT token (silly question but people often forget to do this lol)
a month ago
Yes (shared variables) and i also deploy after setting it
a month ago
After you set the variable in shared variables, you still need to set it on the service by referencing the shared variable via ${{shared.JWT_TOKEN}}, did you do that?
dev
After you set the variable in shared variables, you still need to set it on the service by referencing the shared variable via ${{shared.JWT_TOKEN}}, did you do that?
a month ago
No, how do i go about it
a month ago
You just set the variable to JWT_TOKEN=${{shared.JWT_TOKEN}} in your service settings, assuming JWT_TOKEN is defined within shared variables it should work fine
dev
You just set the variable to JWT_TOKEN=${{shared.JWT_TOKEN}} in your service settings, assuming JWT_TOKEN is defined within shared variables it should work fine
a month ago
This is what i have on my shared variable
Attachments
a month ago
I see this message:
injecting env (0) from .envcan you check if you are trying to load the .env from your app, if you are, can you skip it if NODE_ENV = production?
In theory when you deploy you should get the env variables from the environment, not from a file
fra
I see this message:injecting env (0) from .envcan you check if you are trying to load the .env from your app, if you are, can you skip it if NODE_ENV = production?In theory when you deploy you should get the env variables from the environment, not from a file
a month ago
Can you elaborate more on it?
samsonchinedu
This is what i have on my shared variable
a month ago
It's purple, purple means its not deployed, have you deployed your changes? (Top centre of the screen should be a Deploy button)
After it's deployed, click the eye icon to see if you see the value there, if the value isn't there then it could mean that the shared variable wasnt set, in which case you either need to set it or just set your JWT_TOKEN to have the secret directly within the service itself
dev
It's purple, purple means its not deployed, have you deployed your changes? (Top centre of the screen should be a Deploy button)After it's deployed, click the eye icon to see if you see the value there, if the value isn't there then it could mean that the shared variable wasnt set, in which case you either need to set it or just set your JWT_TOKEN to have the secret directly within the service itself
a month ago
Yes, but i am getting i different error after trying to redeploy
samsonchinedu
Can you elaborate more on it?
a month ago
can you show do you load the env variable in your app?
also which error do you get now?
fra
can you show do you load the env variable in your app?also which error do you get now?
a month ago
app/node_modules/@prisma/client/src/runtime/core/engines/library/LibraryEngine.ts:440
throw new PrismaClientInitializationError(error.message, this.config.clientVersion!, error.error_code)
^
PrismaClientInitializationError: error: Environment variable not found: DATABASE_URL.
--> schema.prisma:7
|
6 | provider = "postgresql"
7 | url = env("DATABASE_URL")
|
Validation Error Count: 1
at r (/app/node_modules/@prisma/client/src/runtime/core/engines/library/LibraryEngine.ts:440:17)
at async Proxy.onModuleInit (/app/prisma/prisma.service.ts:11:9)
at async Promise.all (index 0)
at async callModuleInitHook (/app/node_modules/@nestjs/core/hooks/on-module-init.hook.js:43:5)
at async NestApplication.callInitHook (/app/node_modules/@nestjs/core/nest-application-context.js:242:13)
at async NestApplication.init (/app/node_modules/@nestjs/core/nest-application.js:103:9)
at async NestApplication.listen (/app/node_modules/@nestjs/core/nest-application.js:175:13)
at async bootstrap (/app/src/main.ts:13:3) {
clientVersion: '6.12.0',
errorCode: 'P1012',
retryable: undefined
}
Node.js v22.20.0
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
Stopping Container
a month ago
did you add the DATABASE_URL env? can you please check if you have added all the necessary envs?
fra
did you add the DATABASE_URL env? can you please check if you have added all the necessary envs?
a month ago
Yes i did, can i show you?
dev
Screenshots are always welcome, just becareful not to share secret data
a month ago
Yeah, it okay, it a project i am to test backend strengthen
a month ago
if you have added all the env my feeling is that the app is not picking them up, maybe because is trying to pick them from the .env file, can you show how do you load the envs?
a month ago
Well the fact that properly specifying the JWT_TOKEN solved that part and gave us a new issue, they're probably loading variables correctly and just haven't specified the variables their app needs
fra
if you have added all the env my feeling is that the app is not picking them up, maybe because is trying to pick them from the .env file, can you show how do you load the envs?
a month ago
Here is the screenshot of how i load it
Attachments
dev
Well the fact that properly specifying the JWT_TOKEN solved that part and gave us a new issue, they're probably loading variables correctly and just haven't specified the variables their app needs
a month ago
Maybe
a month ago
That seems fine, you just need to specify the DATABASE_URL as fra said to solve this new issue
samsonchinedu
Yes i did, can i show you?
a month ago
here he said he did add all the envs that's the weird thing
a month ago
you said you are using shared variables, did you share the variables with the service like is written here?
https://docs.railway.com/guides/variables#shared-variables
To use a shared variable, either click the Share button from the Project Settings -> Shared Variables menu and select the services with which to share, or visit the Variables tab within the service itself and click "Shared Variable".fra
you said you are using shared variables, did you share the variables with the service like is written here?https://docs.railway.com/guides/variables#shared-variablesTo use a shared variable, either click the Share button from the Project Settings -> Shared Variables menu and select the services with which to share, or visit the Variables tab within the service itself and click "Shared Variable".
a month ago
I am currently going through it
a month ago
Using shared variables for all your variables is a rather odd way to go about adding variables, what made you choose to do that?
You could alternatively just copy and paste all the variables from shared variables into your service variables if you don't intend on actually sharing the variables with every service in the project
dev
Using shared variables for all your variables is a rather odd way to go about adding variables, what made you choose to do that?You could alternatively just copy and paste all the variables from shared variables into your service variables if you don't intend on actually sharing the variables with every service in the project
a month ago
I only share the variable for jwt_secret
a month ago
Oh, alright, in that case yea you just need to set the missing variables in your service
dev
Oh, alright, in that case yea you just need to set the missing variables in your service
a month ago
I think it should be databasea-url
a month ago
yeah I agree that it might make more sense to put all the envs at the service level instead of shared variables
dev
Your logs says it's DATABASE_URL not databasea-url
a month ago
Yes, it is i am just lazy to write like that
Status changed to Solved dev • about 1 month ago