nuxt / vercel-builder

Vercel Builder for Nuxt
MIT License
645 stars 76 forks source link

FUNCTION_INVOCATION_FAILED error when deploying Nuxt SSR #534

Closed florian-lefebvre closed 3 years ago

florian-lefebvre commented 3 years ago

I know there is this closed issue #530,

@danielroe Ahhh so anything that is imported in nuxt.config must be inside of dependencies instead of devDependencies? That makes sense. Thank you so much! I will close the issue now 😁

so I tried to move all my devDependencies to dependencies, and it didn't change anything. Can you help me @danielroe ?

error

2021-03-26T15:33:43.386Z    undefined   ERROR   Uncaught Exception  {"errorType":"Error","errorMessage":"Could not load Nuxt configuration. Make sure all dependencies are listed in package.json dependencies or in serverFiles within builder options:\n Error: Cannot find module 'esm'\nRequire stack:\n- /var/task/vercel__launcher.js\n- /var/runtime/UserFunction.js\n- /var/runtime/index.js","stack":["Error: Could not load Nuxt configuration. Make sure all dependencies are listed in package.json dependencies or in serverFiles within builder options:"," Error: Cannot find module 'esm'","Require stack:","- /var/task/vercel__launcher.js","- /var/runtime/UserFunction.js","- /var/runtime/index.js","    at Object.<anonymous> (/var/task/vercel__launcher.js:23:13)","    at Module._compile (internal/modules/cjs/loader.js:1063:30)","    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)","    at Module.load (internal/modules/cjs/loader.js:928:32)","    at Function.Module._load (internal/modules/cjs/loader.js:769:14)","    at Module.require (internal/modules/cjs/loader.js:952:19)","    at require (internal/modules/cjs/helpers.js:88:18)","    at _tryRequire (/var/runtime/UserFunction.js:75:12)","    at _loadUserApp (/var/runtime/UserFunction.js:95:12)","    at Object.module.exports.load (/var/runtime/UserFunction.js:140:17)"]}
Unknown application error occurred
Error

package.json

{
  "name": "nuxt",
  "version": "1.0.0",
  "private": true,
  "scripts": {
    "dev": "nuxt",
    "build": "nuxt build --modern",
    "start": "nuxt start",
    "generate": "nuxt generate",
    "analyze": "yarn build -a",
    "vercel": "vercel dev"
  },
  "dependencies": {
    "@nuxtjs/google-adsense": "^1.3.0",
    "@nuxtjs/strapi": "^0.3.1",
    "@nuxtjs/toast": "^3.3.1",
    "@nuxtjs/vercel-builder": "^0.21.2",
    "axios": "^0.21.1",
    "core-js": "^3.8.3",
    "nuxt": "^2.15.3",
    "nuxt-i18n": "^6.22.2",
    "vue-clipboard2": "^0.3.1",
    "vue-country-flag": "^2.0.3"
  },
  "devDependencies": {
    "@nuxtjs/google-analytics": "^2.4.0",
    "@nuxtjs/google-fonts": "^1.2.0",
    "@nuxtjs/tailwindcss": "^4.0.2",
    "@teamnovu/nuxt-breaky": "^1.2.2",
    "nuxt-vite": "^0.0.36",
    "postcss": "^8.2.8",
    "tailwindcss": "^2.0.4",
    "tailwind-stroke-color": "1.0.0",
    "tailwindcss-textshadow": "^2.1.3"
  }
}

nuxt.config.js

import localesFetcher from "./lang/localesFetcher";

export default async function () {
  const locales = await localesFetcher();
  return {
    head: {
      title: "nuxt",
      htmlAttrs: {
        lang: "en",
        class: "custom-scrollbar",
      },
      meta: [
        { charset: "utf-8" },
        { name: "viewport", content: "width=device-width, initial-scale=1" },
        { hid: "description", name: "description", content: "" },
      ],
      link: [{ rel: "icon", type: "image/png", href: "/icon.png" }],
    },
    plugins: [
      // https://github.com/Inndy/vue-clipboard2
      "~/plugins/vue-clipboard2.js",
      // https://github.com/P3trur0/vue-country-flag
      "~/plugins/vue-country-flag.js",
      // https://i18n.nuxtjs.org/callbacks/
      "~/plugins/i18n.js",
    ],
    components: true,
    loading: false,
    build: {
      // extractCSS: true,
      loaders: {
        limit: 0,
      },
    },
    buildModules: [
      // https://go.nuxtjs.dev/tailwindcss
      "@nuxtjs/tailwindcss",
      // https://google-analytics.nuxtjs.org/
      "@nuxtjs/google-analytics",
      // https://vite.nuxtjs.org/
      // "nuxt-vite"
      // https://github.com/teamnovu/nuxt-breaky
      "@teamnovu/nuxt-breaky",
    ],
    modules: [
      // https://i18n.nuxtjs.org/
      "nuxt-i18n",
      // https://github.com/nuxt-community/google-adsense-module
      "@nuxtjs/google-adsense",
      // https://strapi.nuxtjs.org/
      "@nuxtjs/strapi",
      // https://github.com/nuxt-community/community-modules/tree/master/packages/toast
      "@nuxtjs/toast",
      // https://google-fonts.nuxtjs.org/
      "@nuxtjs/google-fonts",
    ],
    i18n: {
      baseUrl: process.env.BASE_URL || "http://localhost:3000",
      strategy: "prefix",
      locales,
      lazy: true,
      langDir: "lang/",
      defaultLocale: "en",
      vueI18n: {
        fallbackLocale: "en",
      },
      detectBrowserLanguage: {
        useCookie: true,
        cookieKey: "i18n_redirected",
        onlyOnRoot: true,
      },
    },
    "google-adsense": {
      // id: "ca-pub-#########"
    },
    strapi: {},
    toast: {
      position: "top-center",
      duration: 1000,
      theme: "tw",
    },
    tailwindcss: {
      jit: true,
      exposeConfig: true,
      viewer: false,
    },
    googleFonts: {
      families: {
        Poppins: [100, 200, 300, 400, 500, 600, 700, 800, 900],
      },
    },
    googleAnalytics: {
      dev: true,
    },
  };
}

vercel.json

{
  "version": 2,
  "builds": [
    {
      "src": "nuxt.config.js",
      "use": "@nuxtjs/vercel-builder",
      "config": {
        "serverFiles": ["locales/**"]
      }
    }
  ],
  "trailingSlash": true,
  "rewrites": [{ "source": "/(.*)", "destination": "/" }],
  "headers": [
    {
      "source": "/_nuxt/(.+)",
      "headers": [
        {
          "key": "Cache-Control",
          "value": "max-age=31557600"
        }
      ]
    }
  ]
}
danielroe commented 3 years ago

@florian-lefebvre You appear to be importing lang/localesFetcher into your nuxt.config. Perhaps you should include that in your serverFiles :upside_down_face:

florian-lefebvre commented 3 years ago

It worked, thanks a lot!