It looks like all the other files like env.production or env.production.local are ignored by the build if standalone option is set to true. During build it looks like it's all read corectly. Console.logs are returing process.env.VARIABLE correctly, but the distribution ran with "node .next/standalone/server.js" is missing variables from env.* files. If I remove .env build is progressing correctly reading env.production.local and env.production but the result is missing all the variables as there was no .env file. Looks like it's the only file respected for standalone. Is that expected behavior?
#.env file is the only one respected by standalone build
1 messages Β· Page 1 of 1 (latest)
π This post has been indexed in our web forum and will be seen by search engines so other users can find it outside Discord
π΅οΈ Your user profile is private by default and won't be visible to users outside Discord, if you want to be visible in the web forum you can add the "Public Profile" role in id:customize
β
You can mark a message as the answer for your post with Right click -> Apps -> Mark Solution
(if you don't see the option, try refreshing Discord with Ctrl + R)
you could try booting your standalone build via dotenvx run or even https://github.com/chihab/dotenv-run
which would do the loading, and inject the env vars into the nextjs process
I'm also working on something new that might help, feel free to send me a DM if you want to try it
Can you test this library to see if it works for you?
You can also try using https://varlock.dev/integrations/nextjs/ to manage your env files, and when you boot your standalone app, use varlock run -- node .next/standalone/server.js
Thanks! That looks like pretty nice plugin, but I have some troubles to set it up. I am getting:
> biogas-resources@0.1.0 dev /home/kalinq/Workspace/biostock/bio-resources
> next dev --turbopack
π¨ process.env.__VARLOCK_ENV is not set π¨
To use this plugin, you must override @next/env with @varlock/next-integration
See https://varlock.dev/integrations/nextjs for more information
/home/kalinq/Workspace/biostock/bio-resources/node_modules/.pnpm/@varlock+nextjs-integration@0.0.2_next@15.3.5_@babel+core@7.28.0_react-dom@19.1.0_react_9059da9ba388feb8adbb5c41696de238/node_modules/@varlock/nextjs-integration/dist/plugin.js:23
throw new Error("VarlockNextWebpackPlugin: __VARLOCK_ENV is not set");
^
Error: VarlockNextWebpackPlugin: __VARLOCK_ENV is not set
at Object.<anonymous> (/home/kalinq/Workspace/biostock/bio-resources/node_modules/.pnpm/@varlock+nextjs-integration@0.0.2_next@15.3.5_@babel+core@7.28.0_react-dom@19.1.0_react_9059da9ba388feb8adbb5c41696de238/node_modules/@varlock/nextjs-integration/dist/plugin.js:23:9)
at Module._compile (node:internal/modules/cjs/loader:1562:14)
at node:internal/modules/cjs/loader:1699:10
at require.extensions..js (/home/kalinq/Workspace/biostock/bio-resources/node_modules/.pnpm/next@15.3.5_@babel+core@7.28.0_react-dom@19.1.0_react@19.1.0__react@19.1.0/node_modules/next/dist/build/next-config-ts/require-hook.js:49:20)
at Module.load (node:internal/modules/cjs/loader:1313:32)
at Function._load (node:internal/modules/cjs/loader:1123:12)
at TracingChannel.traceSync (node:diagnostics_channel:322:14)
at wrapModuleLoad ...
Node.js v22.13.1```
Tho it seems to be overrided correctly:
Legend: production dependency, optional only, dev only
biogas-resources@0.1.0 /home/kalinq/Workspace/biostock/bio-resources (PRIVATE)
dependencies:
@kinde-oss/kinde-auth-nextjs 2.8.2
βββ¬ next 15.3.5 peer
βββ @next/env link:@varlock/nextjs-integration
@next/third-parties 15.3.5
βββ¬ next 15.3.5 peer
βββ @next/env link:@varlock/nextjs-integration
@varlock/nextjs-integration 0.0.2
βββ¬ next 15.3.5 peer
βββ @next/env link:@varlock/nextjs-integration
cookies-next 5.1.0
βββ¬ next 15.3.5 peer
βββ @next/env link:@varlock/nextjs-integration
next 15.3.5
βββ @next/env link:@varlock/nextjs-integration```
oh. I figured it out.
"@next/env": "npm:@varlock/nextjs-integration"```
@lost socket I am encountering pretty much the same issue. Only .env variables are being read and .env.test seems to be ignored.
During the build I can see expected env variables, but when running standalone there're only .env ones.
It looks to me that raw .env is just and only copied into standalone version despite the NODE_ENV or APP_ENV during the build. I would expect generated .env file based on NODE_ENV variable during build, but maybe I am wrong here.
What I really wanted to achieve is standalone version for e2e testing purpose.
Experiencing the same behavior with "@t3-oss/env-nextjs".
Maybe it's just how it is. I handle it by copying the .env.test as .env.production into standalone folder (.next/standalone/.env.production) after the build.
β
Success!
This question has been marked as answered! If you have any other questions, feel free to create another post
Jump to answer
[Click here](#1389201027613593690 message)
Ah yes you must copy them into that folder. Iβll add that to our docs π