nx icon indicating copy to clipboard operation
nx copied to clipboard

Creating a react app using webpack in NX 18 doesn't use historyApiFallback by default

Open observstream opened this issue 1 year ago • 1 comments

Current Behavior

When creating a new react application in Nx 18 with webpack, the historyApiFallback option for the dev server is not set by default. This causes any refresh on a child page to show Cannot GET /page-2. This used to work with Nx 17 by default.used

Expected Behavior

When creating a new React application using Webpack, you should be able to refresh the page on a child page, and it should show the page.

GitHub Repo

https://github.com/jahumes/test-react-webpack-18

Steps to Reproduce

  1. Either download the provided repo, or create a new integrated repo using npx create-nx-workspace
  2. If not using the provided repo, add @nx/react and create a new react application nx g @nx/react:application react-app --routing
  3. Start the application nx run react-app:serve
  4. Visit http://localhost:4200
  5. Scroll to the bottom and click Page 2
  6. Refresh the page

Nx Report

Node   : 20.11.1
OS     : win32-x64
npm    : 10.2.4

nx (global)        : 18.0.5
nx                 : 18.3.4
@nx/js             : 18.3.4
@nx/jest           : 18.3.4
@nx/linter         : 18.3.4
@nx/eslint         : 18.3.4
@nx/workspace      : 18.3.4
@nx/devkit         : 18.3.4
@nx/eslint-plugin  : 18.3.4
@nx/react          : 18.3.4
@nrwl/tao          : 18.3.4
@nx/web            : 18.3.4
@nx/webpack        : 18.3.4
typescript         : 5.4.5
---------------------------------------
Registered Plugins:
@nx/webpack/plugin
@nx/eslint/plugin
@nx/jest/plugin

Failure Logs

No response

Package Manager Version

No response

Operating System

  • [X] macOS
  • [X] Linux
  • [X] Windows
  • [ ] Other (Please specify)

Additional Information

No response

observstream avatar May 04 '24 15:05 observstream

I can confirm this, is there a solution ?

MouaadAitSaid avatar May 04 '24 23:05 MouaadAitSaid

I setup a new project with react and nx 19.0.3 and had to add historyApiFallback to webpack.config.js to make index.html to be served when the app path is not empty. Please fix.

ipassynk avatar May 22 '24 13:05 ipassynk

Any update?

observstream avatar Jun 03 '24 19:06 observstream