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

process is not defined #4264

Open
mankind4dev opened this issue Mar 10, 2024 · 2 comments
Open

process is not defined #4264

mankind4dev opened this issue Mar 10, 2024 · 2 comments

Comments

@mankind4dev
Copy link

mankind4dev commented Mar 10, 2024

import { createApi, fetchBaseQuery } from "@reduxjs/toolkit/query/react";

export const api = createApi({
baseQuery: fetchBaseQuery({ baseUrl: process.env.REACT_APP_BASE_URL }),
reducerPath: "adminApi",
tagTypes: ["Mankind"],
endpoints: (build) => ({
getUser: build.query({
query: (id) => general/user/${id},
providesTags: ["Mankind"],
}),
}),
});

export const { userGetUserQuery } = api;

Please, why these error below when I run npm run dev
api.js:5 Uncaught ReferenceError: process is not defined
at api.js:5:40
(anonymous) @ api.js:5

@phryneas
Copy link
Member

phryneas commented Mar 10, 2024

It seems like your bundler doesn't replace process.env.. Most bundlers should do that by default - what are you using?

Also, this seems to be an access to process your own code...?

Also, please use a more fitting title. For this problem it doesn't really play a role if you want to create a dashboard or build a rocket.

@phryneas phryneas changed the title creating dashboard process is not defined Mar 10, 2024
@saurabhk79
Copy link

Since, you are using vite here, and vite has different way of processing the environment variables. So, simply change

import { createApi, fetchBaseQuery } from "@reduxjs/toolkit/query/react";

export const api = createApi({
baseQuery: fetchBaseQuery({ baseUrl: import.meta.env.VITE_REACT_APP_BASE_URL }), // <---- changed this
reducerPath: "adminApi",
tagTypes: ["Mankind"],
endpoints: (build) => ({
getUser: build.query({
query: (id) => general/user/${id},
providesTags: ["Mankind"],
}),
}),
});

export const { userGetUserQuery } = api;

Now, it would work...

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

3 participants