Next Base Path
See original GitHub issueCurrent Behavior
When I use the base path config and run nx serve myApp
I can load my app on the specified base path, but when I run nx build myApp --prod
& then run the app, the base path is ignored.
Expected Behavior
Should be able to render my app from both dev & production builds on the base path URL
Steps to Reproduce
npx create-nx-workspace@latest
cd my-org/apps/todos
- Edit next.config.js to be
module.exports = { basePath: '/something' };
nx serve todos
You’ll find the todos app onlocalhost:4200/something
👍nx build todos --prod && cp package.json dist/apps/todos && yarn && npx next start
The todos app renders onlocalhost:3000
notlocalhost:3000/something
😢
Environment
nx : Not Found
@nrwl/angular : Not Found
@nrwl/cli : 10.2.1
@nrwl/cypress : 10.2.1
@nrwl/eslint-plugin-nx : 10.2.1
@nrwl/express : Not Found
@nrwl/jest : 10.2.1
@nrwl/linter : 10.2.1
@nrwl/nest : Not Found
@nrwl/next : 10.2.1
@nrwl/node : Not Found
@nrwl/react : 10.2.1
@nrwl/schematics : Not Found
@nrwl/tao : 10.2.1
@nrwl/web : 10.2.1
@nrwl/workspace : 10.2.1
typescript : 3.9.7
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (4 by maintainers)
Top Results From Across the Web
Base Path - next.config.js
Base Path added. To deploy a Next.js application under a sub-path of a domain you can use the basePath config option. ... Note:...
Read more >How to change the base path in nextjs? - Medium
You can change the base path in nextjs. Base path help distribute the nextjs app on a different subdomain. In next/link component, nextjs...
Read more >How to redirect / into basePath in Next.js config?
So every time I enter path / I want to redirect into /docs . Here is what I've tried. module.exports = { basePath:...
Read more >Next.js and GitHub Pages, how the basePath and assetPrefix ...
The basePath configurator allows you to serve your website pages under a subpath with no complex configuration. For example, if you're hosting ...
Read more >Deploy your NextJS Application on a different base path (i.e. ...
To deploy a Next application under a different base path, we need a reverse proxy that creates the mapping from whatever path we...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Hi there @hloughrey ! Thanks for filing an issue!
I think that this is not a bug of Nx, but rather the way Next.js and the
basepath
innext.config.js
works, since the Next.js server uses it.In order to solve your issue and be able to serve your production app using the
next
server from the correctbasePath
from within the builddist
directory of your app, you should copy yournext.config.js
in thedist/apps/todos
directory, next to thepackage.json
.Please let me know if this solves your issue, and if you would like any other help!
Hi @mandarini
Ah, that’s brilliant. I had tried running a Next production build in a non NX project and it worked, but come to think of it, that’s probably because
next.config.js
was at the root as you’ve pointed out. That’s a great help…thank you.