webpack-dev-server shows Cannot GET / in the browser
Cannot GET /Short answer
The dev server started but has no file for the URL you asked for. It serves bundles from memory and other files from devServer.static, which defaults to the public folder. Put an index.html there that loads your bundle, match the public path, and enable historyApiFallback for client-side routes.
Fix it fast
1Find out which cause you have
Open the server's own route that shows what it serves, and read the start-up lines for the static directory.
curl -s http://localhost:8080/webpack-dev-server | head -402Match what you see, then jump to its fix
- 1
Cannot GET / on the root URL, while the start-up line names a directory that has no index.htmlNo index.html in the static directoryFix - 2
The page loads but the script returns 404, or the URL you open differs from output.publicPathThe bundle is requested from a different path than it is served onFix - 3
Cannot GET /about only on reload or a direct link; / worksA client-side route is requested directlyFix
- 1
What does the error look like?
Cannot GET /[webpack-dev-server] Content not from webpack is served from '/app/public' directory
Cause 1 of 3
No index.html in the static directory
1Check
Compare the directory printed by the server with the files in it. The default is public in the folder you started from.
ls public2Fix
Create an index.html there with a script tag for your bundle, or point static at the folder that has it. webpack-dev-server does not insert script tags for you.
devServer: {
static: { directory: path.join(__dirname, 'public') },
},3Verify
Reload the page; the HTML loads.
curl -I http://localhost:8080/Confirmed by webpack.js.org
Cause 2 of 3
The bundle is requested from a different path than it is served on
1Check
The dev server serves bundles at the devServer host and port plus output.publicPath and output.filename, from memory, not from dist.
curl -I http://localhost:8080/main.js2Fix
Make the script tag match, or set the public path used by the dev middleware.
devServer: {
devMiddleware: { publicPath: '/' },
},3Verify
The bundle URL returns 200.
curl -I http://localhost:8080/main.jsConfirmed by webpack.js.org
Cause 3 of 3
A client-side route is requested directly
1Check
The server has no file for /about because the router handles it in the browser.
curl -I http://localhost:8080/about2Fix
Turn on historyApiFallback so index.html is served in place of 404 responses.
devServer: {
historyApiFallback: true,
},3Verify
Reload on the route; the app loads.
curl -I http://localhost:8080/aboutConfirmed by webpack.js.org
How do I stop it coming back?
- Keep one index.html in the folder devServer.static points to and commit it.
- Set an absolute path for static.directory instead of relying on the working directory.
- Add historyApiFallback to any single-page app config from the start.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
Related fixes
Web apps
Invalid Host header from webpack-dev-server
Invalid Host header
The dev server checks the Host header of every request.
3 causes, each with a fixBack end
ng serve says it cannot determine the project or target
Cannot determine project for command.
The Angular CLI looked through angular.json for a project that defines the target you asked for (serve, build, test) and found none, or found several and could not pick one.
3 causes, each with a fixBack end
ng fails with Cannot find module @angular/cli/bin/ng
Cannot find module '@angular/cli/bin/ng'
The ng command is the entry point to the Angular CLI package.
2 causes, each with a fixBack end
Angular app shows 'Cannot GET /' when served by a Node.js server
Cannot GET /dashboard
Cannot GET / is Express saying no route or file matches the request.
3 causes, each with a fixBack end
ng serve cannot find the dev-server builder package
Could not find the implementation for builder @angular/build:dev-server
The builder named in angular.json (for example @angular-devkit/build-angular:dev-server) is looked up as an npm package starting from the workspace root.
3 causes, each with a fixBack end
Angular build says it cannot resolve '@angular/localize/init'
Can't resolve '@angular/localize/init' in '/usr/src/app/src'
The build imports @angular/localize, and that package is not in node_modules.
2 causes, each with a fix