-
Notifications
You must be signed in to change notification settings - Fork 27.2k
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
Router push basePath ignored #19099
Comments
Here's my Dockerfile: FROM node:15.1.0-alpine
# setting working directory. All the path will be relative to WORKDIR
WORKDIR /app
# installing dependencies
COPY package.json .
COPY yarn.lock .
RUN yarn install
# copying source files
COPY . .
# building app
RUN yarn build
# running the app
CMD [ "yarn", "start" ]
# expose port
EXPOSE 3000 Here's my next.config.js file: const basePath = process.env.BASE_PATH ?? '';
const environment = process.env.ENVIRONMENT ?? 'UNKNOWN';
const apiBaseUri = process.env.API_BASE_URI ?? '';
/**
* The main Next.js configuration.
* see: https://nextjs.org/docs/api-reference/next.config.js/environment-variables
*/
module.exports = {
basePath,
publicRuntimeConfig: {
basePath,
environment,
i18n: { lookupCookie: 'locale' },
apiBaseUri
}
}; |
Check related issue comment #18984 (comment) |
The basePath doesn't seems to be something that can be changed via a environement variable when running a docker container. It doesn't seem to have a way to set it with the newer version of setting environment virables. https://nextjs.org/docs/basic-features/environment-variables It this config is only set at build time (next.config.js)? https://nextjs.org/docs/api-reference/next.config.js/basepath |
@sebascomeau correct, the
Looks like we could make this clearer in the above mentioned docs so I'm going to re-open to track |
Is there a way to push environement variable from a container to a docker image? or the docker image needs to have a .env file for next used them? I tried to use process.env.NEXT_PUBLIC_API_BASE_URL from the client-side and in the docker image I dont have any .env but I am pushing NEXT_PUBLIC_API_BASE_URL when running the container. But the variable is undefined in client-side. What the good way to push environement variable from a container to the docker image? I would be nice to have a way to modified the basePath config the same way. That running locally I can test the app from http://localhost:3000 and in a hosting environement http://domain.com/resource-finder so that I can push NEXT_PUBLIC_BASE_PATH:/resource-finder to a container. |
Requiring that Some organizations (ours included) configure many environments as Some organizations (ours included) also mandate that build artifacts be promoted from environment to environment without rebuilding (one of the 12-factor rules). So, is there any way to achieve what @sebascomeau is looking to do? I am open to submitting a PR if you would kindly provide a starting point. I am not familiar with the next.js project so I have no idea where to start looking. |
@sebascomeau: one way to solve this problem would be to trigger an npm build at container startup. This would generate the client-side files according to how the environment variables are set. This is really only a solution for containers, and would lead to pretty large images (thanks, It isn't a great solution, in my opinion.. but I'm leaving it here in case others stumble across this issue and are in a bind. |
@ijjk did you had time to check @gregory-j-baker comments above? Thanks |
Is their a way to push process.env.NEXT_PUBLIC variables to a container that the app would pickup and expose them to the client without an .env file? |
@sebascomeau |
So does everyone using next.js just deploy their applications to the same base path.. everywhere? Or do they have different builds for each differing base path? I'm interested in knowing what the community is doing. |
This issue has been automatically locked due to no recent activity. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you. |
Bug report
Describe the bug
We are using basePath for our frontend and when calling Router.push() the basePath is ignored. This seems to only be an issues in a docker image.
Expected behavior
Calling router.push("/ac") with basePath "/resource-finder" in config it should redirect to "/resource-finder/ac".
System information
Additional context
I already opened a ticket for same behavior with SSR #18984
The text was updated successfully, but these errors were encountered: