-
Notifications
You must be signed in to change notification settings - Fork 27k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Generated static files html files have wrong assets paths #8158
Comments
Hey @emuraton! The Sorry for the confusion! |
Hey @Timer, Thanks for the clarification, but right now after build time, I try to handle the static files with I will set |
@emuraton You should not set It sounds like you're trying to do something non-standard, you do not need to handle serving any of these files yourself. Can you please explain what you're trying to accomplish more? |
I want Next.js to output static files for me, and then I want to serve my static files with https://www.npmjs.com/package/serve. |
It sounds like you're looking for the |
@emuraton sorry, but we cannot provide further support without a reproducible demo provided. |
Ok thanks for your time 👍 |
Hi, i came across the same Problem as @emuraton mentioned. After i do the basic export command and open the generated index.html i get this error If i add a |
we are hitting the same issue here to fix this issue from our side we had to set distDir to _next we were following the instructions inside the docs just clarification that I am not saying this is the standard i am just this was a fix to issue appeared |
|
Hi, why is this issue closed? It's still happening!!! |
@cargallo not sure what you're referring to, this issue has a reply: #8158 (comment) It's impossible to help you based on "Why is this closed" without a full reproduction or even any information about your issue. |
Hi @timneutkens I followed the start learning of the oficial nextjs web. If you run "next build && next export" the resulting html site (that command is for generating just a static site wich not requires nodejs server or whatever server) the links of the css and js resources attached by nextjs, their path is in this way
The problem is not in wich name the folder has but in the way that it is referenced since in plain HTML it has to have a dot before the first slash, like this
I think that if nextjs can refer the files in this way it could be run in both, plain HTML and nodejs server or vercel environment. Reggards, |
Hi @timneutkens , could you check the detailed infromation? Thanks in advance! |
The out directory has to be hosted through a web server, we currently do not support using the html standalone |
I don't understand therefore what is next export command for? And it's just easy to implement it has no sense at all. |
DO NOT USE THIS SOLUTION ANY MORE !!! To automate the steps commented above:
Then, add this two scripts in your package.json
Then just call
Explanation: The build-static-repair-index script will replace /_next/static with ./_next/static in the index.html file inside out folder wich is generated when you export your entire site to plain html wich can run standalone without any server. Hope this helps. Reggards, |
@cargallo it does yes, thank you. And it works just fine. Shame, this should be a very prominent configuration setting IMO. Gracias :) |
I experienced a similar issue all of a sudden which I thought was extremely weird. After Then I emptied my bin (or trashcan on Windows)... and then it started working again as expected. |
I don't understand how more people are not complaining about this. |
Thanks @cargallo 👍 [EDIT] I've set my config to the following and it did the trick: next.config.js
Generated output: index.html
@cargallo if you haven't done so already, you might want to use this instead of npm: replace-in-files-cli method 👍 |
I hosted the content of "out" folder on a free server like 000webhost (doesn't have node) and works pretty well. But... the first time I had this trouble with a laragon server. After that I maked a tool for fix this. Right now, after to host on a php server, I know that the tool is useless, but if it is util for you, use it tool |
With Sass I configured my next.config.js as follows const withPlugins = require("next-compose-plugins"); module.exports = withPlugins([[withSass({ |
It's still happening! |
In my case I am having multiple sub folders based on navigation structure where prefixing "." in front of "/_next/" is not helping out. Currently as a workaround I am using "serve" and using the "localhost" url to generate the critical CSS manually. |
@OHHAKO Sorry for the late reply. Are you putting your image resources under ./public folder? ExampleWhen you layout the public folder like the following:
Performing a "next build" + "next export", the images will produce an out folder with:
Then you can reference the images in your project like: pages/index.js
OR via a component
./pages/index.js
NOTEYou will get an error if you attempt to use the inbuilt "next\Image" during an export pages/index.js
Error:
|
Hey folks. The issue being experienced by most of the comments above appears to be because once a Imagine a basic project folder set up, something like:
Then start an http server with the The asset path Next.js uses ASSUMES that the out folder will be the root of your web server host. Modifying the assetPrefix to "." works for the above layout, but when you try to nest your pages any further it fails again. e.g.
Now when you access Modifying the With a next.config.js of
But then, when you access The _next folder is assumed to be Furthermore, client-side routing will work and render the pages but refreshing will 404 because the navigated URL changes from All of this is down to the relative vs absolute paths being used or not. The question becomes, how do you configure Next.js to output HTML with paths that will operate without knowing ahead of time what folder or sub-folder they will be served from? I think many people commenting assume that the paths would take into account their position within the file tree when they are exported. At the compile time it seems totally possible to know the relative path to the root of the _next folder from any page or component that might be using it but the URLs do not resolve that way at present unless I'm missing some config flag? I read the docs extensively to try and solve this one! Essentially, at present as far as I can tell, you need to modify the config according to the place the code is going to be deployed (see |
Thanks to all of you who took time to share your solutions to this issue. I like next.js, but I have been very frustrated as I ran into the same issues listed above. If nothing else, the next documentation should be more clear about the limitations of SSG. It isn't what I consider "true" SSG given the implicit dependency that remains on the next server. |
well, like every one else I had faced this issue of wrong assets paths and it did not get solved by adding Then create a
Add the followings to your
now, after runing the scripts you must be able to serve the Edit-2: as @peterDuot-stationfive mentioned it should be |
create a file named next.config.js Use the basePath property to define your server path but only in production builds: If your favicon does not serve because you are using a subfolder on your domain, use a conditionnal check like this when you define favicon link: |
should be |
This issue has been automatically locked due to no recent activity. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you. |
Bug report
Describe the bug
I'm tried to generate a static site with Next js
v9.0.2
and got assets linking by default to/_next/static/something/something.js
. But by default build and export create a folder.next
.I think its related to: https://github.com/zeit/next.js/blob/4bcf6aabe7af477a8e58893f03622d84047abf2b/packages/next/pages/_document.tsx#L410
To Reproduce
Expected behavior
Generated path should begin with
./next/
Screenshots
System information
The text was updated successfully, but these errors were encountered: