I'm a newbie in react. I've done a project and for static HTML export, I used "next build && next export" in package.json, and npm run the build command. It also gives me an out folder. The problem is when I try to access HTML files from our folder locally and with a live server, It shows only HTML content without CSS and js. I tried many ways but can't figure out the problem. If anyone helps me with this, I'll be very very thankful to him. Thanks in advance.
CodePudding user response:
next export allows you to export your Next.js application to static HTML, which can be run standalone without the need of a Node.js server. It is recommended to only use next export if you don't need any of the unsupported features requiring a server.
If you're looking to build a hybrid site where only some pages are prerendered to static HTML, Next.js already does that automatically
CodePudding user response:
I have faced same problem.
In my case, Changing src
value solved the problem.
Here is the exact steps.
- build your project
- inside build folder there's index.html
- change
<script src="/static/js/12345.js">
to<script src="./static/js/12345.js">
(add "." before "/") - Do same thing to
<link href="/static/css/main.b57f21b0.css" rel="stylesheet">
and<link rel="icon" href="/favicon.ico"/>
and<link rel="manifest" href="/manifest.json"/>
and other file structure string if exists. - You solved the problem.