image: Nuxt Generate does not produce images
Nuxt version: 2.15.3 @nuxt/image version: 0.4.4 target: ‘static’
I have been using the module in dev mode with no problems. However, when trying to generate a static site using nuxt generate no images are produced by @nuxt/image and all images on the site 404. The generated image URLs point to _ipx/IMAGE_PATH but this is not in the dist folder of the Nuxt project.
I have tried with a fresh Nuxt project with only @nuxt/image added and get exactly the same issue. Running nuxt generate produces no errors in the CLI and the site builds without a problem. The images are just not generated.
Any help on this would be greatly appreciated.
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 1
- Comments: 27 (7 by maintainers)
For what it’s worth I was able to get it working on local dev with “npm run generate” and on Vercel with the following config:
Using “Nuxt”: “^3.6.5” and “@nuxt/image”: “^1.0.0-rc.1”, nuxt generate does not seem to generate static images. In
nuxt.config.tsssr: true,. Trying to setimage: { provider: 'static' }produces an error on the frontend:Error: Unknown provider: static.Locally everything works, here is an example of the file produced:
/_ipx/w_40/img/background/plain.webp. The_ipxfolder is not generated in.outputfolder after runningnuxt generate.@farnabaz Replicating my code on template.nuxtjs.org resulted in the module working how it should. After going through the code and trying to spot differences it looks like having
ssr: falseset in the nuxt.config.js was preventing nuxt/image from running correctly duringyarn generate. When runningyarn create nuxt-app <project-name>and selecting static as the target mode, this flag is added to the config by default. If it’s not a bug, this might need a warning added in the documentation for the module as I couldn’t find information about it currently.I can confirm as per @danielroe 's suggestions you need to have both
ssr: trueandtarget: staticset in yournuxt.config.jsfor this to work. (Confirmed to be working with Vercel, Netlify and Layer0 and local development for static content.)Someone should document this. (Shuffles away into the darkness).
Would you try again with 0.4.8 and prepare a reproduction if it’s still not working? 🙏
Will this issue still exist when migrating to Nuxt 3 ? I would love to benefit from Nuxt Image with a generated site but most providers like Cloudinary are really pricy, will there be a way to work with Nuxt Image and locals images in Nuxt 3 (
ssr: false/target: static) ?BE CAREFUL WITH CONDITIONNAL RENDERING:
I used v-if for a component with NuxtImg inside of it, when i just change to v-show it generates my img inside ipx folder… maybe it’s because v-show generates the DOM of my component but not the v-if.
Also i used NuxtImg inside LToopTip of leaflet and it doesn’t work as well (inside v-for) so i just change to default html
and it works (but no webp compression with nuxt image conf so just do-it-yourself -> https://squoosh.app/ works well)
Info :
Maybe related problem: #689
The key for me was
provider: 'static'and then images got generated, even from remote sources.We saw the same issue, as described above and after updating to
0.4.8is works without settingprovideror `dir. At the end of the generate-process it shows a list of all generated images:@danielroe This is a really cool feature to have, thanks for putting in the work!