質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.49%
Nuxt.js

Nuxt.jsは、ユニバーサルなSPAが開発可能なVue.jsベースのフレームワーク。UIの描画サポートに特化しており、SSRにおけるサーバーサイドとクライアントサイドのUIレンダリングなどさまざまな機能を持ちます。

Q&A

解決済

1回答

2575閲覧

VercelにNuxt(SSR)をデプロイしたい

yoko394

総合スコア6

Nuxt.js

Nuxt.jsは、ユニバーサルなSPAが開発可能なVue.jsベースのフレームワーク。UIの描画サポートに特化しており、SSRにおけるサーバーサイドとクライアントサイドのUIレンダリングなどさまざまな機能を持ちます。

0グッド

0クリップ

投稿2020/09/08 16:35

前提・実現したいこと

SSRのNuxtをVercel(Now.sh)にデプロイしていますが、エラーが出てビルドが失敗します。

Vercelのビルド設定

  • Githubのブランチにcommitしたらビルドする設定
  • BUILD COMMAND: yarn run dev (nuxt-ts buildとなる)
  • OUTPUT DIRECTORY: dist
  • DEVELOPMENT COMMAND: nuxt

発生している問題・エラーメッセージ

VercelのBuild Logsからエラー部分だけ抜粋

FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory
ERROR RpcIpcMessagePortClosedError: Process 1519 exited [SIGABRT]. ERROR Issues checking service aborted - probably out of memory. Check the memoryLimit option in the ForkTsCheckerWebpackPlugin configuration.
✔ Client: Compiled with some errors in 1.13m
Module not found: Error: Can't resolve 'ts-loader' in '/vercel/59fe5036'
✖ Nuxt Fatal Error Error: Nuxt build error
Error: Command failed with exit code 1: npx nuxt build --standalone --no-lock --config-file "nuxt.config.js" 15:10:03.009 at makeError (/vercel/38aa1a6d27b6283d/.build-utils/.builder/node_modules/execa/lib/error.js:59:11) 15:10:03.009 at handlePromise (/vercel/38aa1a6d27b6283d/.build-utils/.builder/node_modules/execa/index.js:114:26) 15:10:03.009 at processTicksAndRejections (internal/process/task_queues.js:97:5) 15:10:03.009 at async Object.build (/vercel/38aa1a6d27b6283d/.build-utils/.builder/node_modules/@nuxtjs/vercel-builder/lib/build.js:124:5) 15:10:03.009 at async buildStep (/var/task/sandbox-worker.js:21075:20) 15:10:03.009 at async mainSub (/var/task/sandbox-worker.js:20796:9) 15:10:03.009 at async main (/var/task/sandbox-worker.js:20658:5) {

該当のソースコード

ビルドに関係すると思われる以下のソースコードを載せます。

package.json

json

1 2{ 3 "name": "AppName", 4 "version": "1.0.0", 5 "private": true, 6 "scripts": { 7 "dev": "nuxt-ts", 8 "build": "nuxt-ts build ", 9 "start": "nuxt-ts start", 10 "generate": "nuxt-ts generate", 11 "lint:js": "eslint --ext .js,.vue --ignore-path .gitignore .", 12 "lint": "yarn lint:js" 13 }, 14 "dependencies": { 15 "@nuxt/content": "^1.5.0", 16 "@nuxt/typescript-runtime": "^1.0.0", 17 "@nuxtjs/axios": "^5.12.0", 18 "@nuxtjs/proxy": "^2.0.1", 19 "@nuxtjs/pwa": "^3.0.0-beta.20", 20 "@nuxtjs/dotenv": "^1.4.1", 21 "@nuxtjs/vuetify": "^1.11.2", 22 "@nuxt/typescript-build": "^2.0.2", 23 "firebase": "^7.18.0", 24 "firebaseui": "^4.6.1", 25 "konva": "^7.0.6", 26 "nuxt": "^2.14.0", 27 "vue-konva": "^2.1.4", 28 "vuex-persistedstate": "^3.1.0", 29 "nuxt-property-decorator": "^2.7.2" 30 }, 31 "devDependencies": { 32 "@nuxt/types": "^2.14.0", 33 "@nuxtjs/eslint-config": "^3.1.0", 34 "@nuxtjs/eslint-config-typescript": "^3.0.0", 35 "@nuxtjs/eslint-module": "^2.0.0", 36 "@nuxtjs/style-resources": "^1.0.0", 37 "babel-eslint": "^10.1.0", 38 "eslint": "^7.5.0", 39 "eslint-config-prettier": "^6.11.0", 40 "eslint-plugin-nuxt": "^1.0.0", 41 "eslint-plugin-prettier": "^3.1.4", 42 "faker": "^4.1.0", 43 "firebase-admin": "^9.1.0", 44 "firebase-tools": "^8.7.0", 45 "prettier": "^2.0.5" 46 } 47} 48

vercel.json

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

nuxt.config.js

js

1import colors from 'vuetify/es5/util/colors' 2 3export default { 4 /* 5 ** Nuxt rendering mode 6 ** See https://nuxtjs.org/api/configuration-mode 7 */ 8 mode: 'universal', 9 /* 10 ** Nuxt target 11 ** See https://nuxtjs.org/api/configuration-target 12 */ 13 target: 'server', 14 /* 15 ** Headers of the page 16 ** See https://nuxtjs.org/api/configuration-head 17 */ 18 head: { 19 titleTemplate: '', 20 title: '', 21 22 ], 23 link: [ 24 { 25 rel: 'icon', 26 sizes: '16x16', 27 type: 'image/png', 28 href: '/favicon-16.png', 29 }, 30 { 31 rel: 'icon', 32 sizes: '32x32', 33 type: 'image/png', 34 href: '/favicon-32.png', 35 }, 36 { 37 rel: 'icon', 38 sizes: '48x48', 39 type: 'image/png', 40 href: '/favicon-48.png', 41 }, 42 { 43 rel: 'icon', 44 sizes: '62x62', 45 type: 'image/png', 46 href: '/favicon-62.png', 47 }, 48 // apple touch icon 49 { 50 rel: 'apple-touch-icon', 51 sizes: '180x180', 52 href: '/apple-touch-icon.png', 53 }, 54 ], 55 }, 56 /* 57 ** Global CSS 58 */ 59 css: [], 60 /* 61 ** Plugins to load before mounting the App 62 ** https://nuxtjs.org/guide/plugins 63 */ 64 65 plugins: [ 66 { src: '~/plugins/vue-konva', ssr: false }, 67 { src: '~/plugins/firebase' }, 68 { src: '~/plugins/persistedstate', ssr: false }, 69 ], 70 71 /* 72 ** Auto import components 73 ** See https://nuxtjs.org/api/configuration-components 74 */ 75 components: true, 76 /* 77 ** Nuxt.js dev-modules 78 */ 79 buildModules: ['@nuxt/typescript-build', '@nuxtjs/vuetify'], 80 /* 81 ** Nuxt.js modules 82 */ 83 modules: [ 84 // Doc: https://axios.nuxtjs.org/usage 85 '@nuxtjs/axios', 86 // '@nuxtjs/pwa', 87 // Doc: https://github.com/nuxt/content 88 '@nuxt/content', 89 '@nuxtjs/style-resources', 90 '@nuxtjs/dotenv', 91 ], 92 93 styleResources: { 94 scss: ['./assets/vars/*.scss'], 95 }, 96 97 /* 98 ** Axios module configuration 99 ** See https://axios.nuxtjs.org/options 100 */ 101 axios: {}, 102 103 /* 104 ** Content module configuration 105 ** See https://content.nuxtjs.org/configuration 106 */ 107 content: {}, 108 /* 109 ** vuetify module configuration 110 ** https://github.com/nuxt-community/vuetify-module 111 */ 112 vuetify: { 113 customVariables: ['~/assets/variables.scss'], 114 theme: { 115 dark: false, 116 white: true, 117 themes: { 118 dark: { 119 primary: colors.blue.darken2, 120 accent: colors.grey.darken3, 121 secondary: colors.amber.darken3, 122 info: colors.teal.lighten1, 123 warning: colors.amber.base, 124 error: colors.deepOrange.accent4, 125 success: colors.green.accent3, 126 } 127 }, 128 }, 129 }, 130 /* 131 ** Build configuration 132 ** See https://nuxtjs.org/api/configuration-build/ 133 */ 134 build: { 135 extend(config, { isDev, isClient, isServer }) { 136 if (isServer) { 137 config.externals = { 138 '@firebase/app': 'commonjs @firebase/app', 139 '@firebase/firestore': 'commonjs @firebase/firestore', 140 } 141 } 142 }, 143 }, 144} 145

試したこと

FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory

上記のエラーよりメモリが足りていないと考え、VercelのBuild Commandを以下のように変更しました。

nuxt-ts build --max-old-space-size=4096

[参考] FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory in ionic 3

結果、同じエラーメッセージが発生し、ビルドが失敗しました。

また、以下の記事より
[Qiita] Vercel(Now.sh)にNuxt.js(SSR)をデプロイすると、Firebase関連でSSR時にNuxt.js Internal Server Errorになるのを修正する
firebase関連でエラーが出るようなので、記事の通りにnuxt.config.jsを修正しました。

js

1// nuxt.config.js 2 build: { 3 extend(config, { isDev, isClient, isServer }) { 4 if (isServer) { 5 config.externals = { 6 '@firebase/app': 'commonjs @firebase/app', 7 '@firebase/firestore': 'commonjs @firebase/firestore', 8 } 9 } 10 }, 11 }

結果、同じエラーメッセージが発生し、ビルドが失敗しました。

現在考えている原因

  • firebaseの通信のため、コンポーネント内でasyncDataを使っている → 通信の処理を./api/以下で実装して、vercel.jsonに登録すべきか?

  • 以下の記事より、/staticの位置が問題?

[Stack Overflow] now dev resulting in intermittent by frequent `FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory

補足情報

  • nodeのバージョン: v14.8.0

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

自己解決

自己解決しました。
build commandが違っていたようです。

投稿2020/09/10 16:49

yoko394

総合スコア6

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.49%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問