image icon indicating copy to clipboard operation
image copied to clipboard

bug: mkdir /var/task/.vercel_build_output

Open oritwoen opened this issue 3 years ago • 13 comments

After a lot of effort, I managed to create a "working" build @nuxt/image in conjunction with @nuxt/vercel-builder in relation to issue: https://github.com/nuxt/image/issues/344.

Only now there is a completely different problem. Upon entering any subpage, Vercel Logs report:

[GET] /
18:06:12:91
FATAL  ENOENT: no such file or directory, mkdir '/var/task/.vercel_build_output'2021-09-13T16:06:14.275Z	undefined	ERROR	λ Error while initializing nuxt: [Error: ENOENT: no such file or directory, mkdir '/var/task/.vercel_build_output'] {  errno: -2,  code: 'ENOENT',  syscall: 'mkdir',  path: '/var/task/.vercel_build_output'}RequestId: 2b315c53-269f-49dd-bc50-fb26bec43f43 Error: Runtime exited with error: exit status 1Runtime.ExitError

oritwoen avatar Sep 13 '21 16:09 oritwoen

/cc @danielroe

pi0 avatar Sep 14 '21 19:09 pi0

This is still an issue, any movement on resolving this?

jonathanmelville avatar Dec 31 '21 18:12 jonathanmelville

For anybody else who comes across this issue, the only working solution for using @nuxt/image with vercel-builder seems to be using the the IPX provider.

jonathanmelville avatar Jan 02 '22 21:01 jonathanmelville

@jonathanmelville, would you be able to share more details around your setup? I'm stuck going around in circles with IPX configuration.

lexvzalingen avatar Jan 07 '22 19:01 lexvzalingen

@lexvzalingen Yeah it's kind of a headache to get it working.

  1. You need to install ipx as a dependency in your project: npm i ipx
  2. Now create this file in your project server/middleware/ipx.js. The contents of that file should look something like this (you will need to update the values of the domains and aliases to your own if you have any):
import { createIPX, createIPXMiddleware } from 'ipx'

// https://github.com/unjs/ipx
const ipx = createIPX({
  dir: '', // absolute path to images dir
  domains: ['https://scontent.cdninstagram.com'], // allowed external domains (should match domains option in nuxt.config)
  alias: {
    instagram: 'https://scontent.cdninstagram.com',
  },
  sharp: {}, // sharp options
})

export default createIPXMiddleware(ipx)
  1. Now your nuxt.config.js config should look something like you see below. Again update domains/alias to match your own. In my case I'm just using it to resize images from Instagram's Basic Display API.
// nuxt.config.js

export default {
       image: {
    provider: 'ipx',
    domains: ['https://scontent.cdninstagram.com'],
    presets: {
      instagram: {
        modifiers: {
          format: 'jpg',
          width: 400,
          height: 400,
        },
      },
    },
    alias: {
      instagram: 'https://scontent.cdninstagram.com',
    },
  },
}
  1. And finally, load your middleware:
// nuxt.config.js 

export default {
      serverMiddleware: [{ path: '/_ipx', handler: '~/server/middleware/ipx' }]
}

That should build and run @nuxt/image on Vercel SSR with @vercel/builder using the ipx provider.

jonathanmelville avatar Jan 07 '22 19:01 jonathanmelville

I forgot one final step, you need to expose your server/middleware directory to Vercel during the build.

In your vercel.json file:

{
  "version": 2,
  "builds": [
    {
      "src": "nuxt.config.js",
      "use": "@nuxtjs/vercel-builder",
      "config": {
        "serverFiles": [
          "server/middleware/**"
        ]
      }
    }
  ]
}

jonathanmelville avatar Jan 07 '22 20:01 jonathanmelville

@lexvzalingen Did you get it working?

jonathanmelville avatar Jan 12 '22 16:01 jonathanmelville

I got it to work just now, thanks a million @jonathanmelville! I had to apply this patch too: https://github.com/nuxt/image/issues/434

All good now, thanks a lot.

lexvzalingen avatar Jan 17 '22 20:01 lexvzalingen

@jonathanmelville I'm in the same situation: SSR deployed in Vercel using vercel-builder and ipx as provider.

My configuration is almost the same you posted above, but in my case I'm not able to set the dir for display local files in Vercel. I've the images stored in static/images/... , and I always receive a 404 from IPX: IPX: File not found: /var/task....

How are you displaying your static images?

pablogtrz avatar Jan 21 '22 16:01 pablogtrz

@pablogtrz In my case I'm not using it to transform local images, only to size down remote images returned from Instagram's Basic Display.

jonathanmelville avatar Jan 21 '22 17:01 jonathanmelville

@pablogtrz In my case I'm not using it to transform local images, only to size down remote images returned from Instagram's Basic Display.

Thanks for the quick answer! I'll keep trying.

@lexvzalingen did you face this problem?

pablogtrz avatar Jan 21 '22 17:01 pablogtrz

I was remove @nuxt/image and it's worked for me!

wyuten avatar May 10 '22 12:05 wyuten

Is there a way to use the vercel edge network provider with nuxt ssr?

SushyDev avatar Jun 11 '22 17:06 SushyDev

When deploying your nuxt applications to Vercel platform, image module can use Vercel's Edge Network to optimize images on demand.

This provider will be enabled by default in vercel deployments.

You can set default provider using NUXT_IMAGE_PROVIDER environment variable. Providers below, are automatically detected: Vercel

Setting the NUXT_IMAGE_PROVIDER Environment Variable in Vercel as cloudinary allowed me to get around the reported error.

cmegalo avatar Feb 15 '23 18:02 cmegalo

This is no longer reproducible for me.

danielroe avatar Apr 22 '24 13:04 danielroe