question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Current 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

  1. npx create-nx-workspace@latest Screenshot 2020-09-28 at 16 36 42
  2. cd my-org/apps/todos
  3. Edit next.config.js to be module.exports = { basePath: '/something' };
  4. nx serve todos You’ll find the todos app on localhost:4200/something 👍
  5. nx build todos --prod && cp package.json dist/apps/todos && yarn && npx next start The todos app renders on localhost:3000 not localhost:3000/something 😢 Screenshot 2020-09-28 at 16 28 10

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:closed
  • Created 3 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
mandarinicommented, Sep 29, 2020

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 in next.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 correct basePath from within the build dist directory of your app, you should copy your next.config.js in the dist/apps/todos directory, next to the package.json.

Please let me know if this solves your issue, and if you would like any other help!

1reaction
hloughreycommented, Sep 29, 2020

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found