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

Can't pull environment variables in TypeScript + Tailwind project #188

Closed
Dnguye92 opened this issue Jun 10, 2021 · 5 comments
Closed

Can't pull environment variables in TypeScript + Tailwind project #188

Dnguye92 opened this issue Jun 10, 2021 · 5 comments
Assignees

Comments

@Dnguye92
Copy link

I created a .env file in root with a hand full of NEXT_PUBLIC_ environment variables. Trying to log them from /pages/index.tsx but I'm not seeing any of them.

Any clue?

@saltyshiomix
Copy link
Owner

@Dnguye92

I think we should locate .env file in the renderer folder.

Could you try it?

@frans-slabbekoorn
Copy link

frans-slabbekoorn commented Feb 11, 2022

You can load the environment variables into process.env using the dotenv package
You should load them in the main process (background.js) like this:

import { config } from 'dotenv';
import isDev from 'electron-is-dev';

config({
    path: isDev ? '.env.development' : '.env.production',
});

.env.development:

NODE_ENV="development"
CUSTOM_VAR=123
NEXT_PUBLIC_CUSTOM_VAR=456

When prefixed with NEXT_PUBLIC_ you can access them in the renderer/next.js process

@saltyshiomix
Copy link
Owner

If any troubles or updates, feel free to reopen the issue 🙏

@jt-l
Copy link

jt-l commented Jan 2, 2024

You can load the environment variables into process.env using the dotenv package You should load them in the main process (background.js) like this:

import { config } from 'dotenv';
import isDev from 'electron-is-dev';

config({
    path: isDev ? '.env.development' : '.env.production',
});

.env.development:

NODE_ENV="development"
CUSTOM_VAR=123
NEXT_PUBLIC_CUSTOM_VAR=456

When prefixed with NEXT_PUBLIC_ you can access them in the renderer/next.js process

This does not appear to work for builds, e.g., 'nextron build' -- any thoughts?

@frans-slabbekoorn
Copy link

frans-slabbekoorn commented Jan 8, 2024

@jt-l I'm currently not using nextron, when I get back to it i will take a look at this. Sorry!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants