Nuxt.JSで作成したブログをNetlifyでデプロイすると、
1「TypeError [ERR_HTTP_INVALID_HEADER_VALUE]: Invalid value "undefined" for header "X-API-KEY"」といったエラーがでてしまいます。原因と対策をご存知の方はいらっしゃいませんか? 2X-API-KEY は、.envファイルにて、 3BASE_URL=http://localhost:3000 4API_KEY=○○○○○○○○○○○ 5API_URL=○○○○○○○○○○○ 6 7nuxt.config.jsにて、 8const { API_KEY,API_UR } = process.env 9 10と設定しています。 11そして、/blog/index.vueにて、 12import axios from 'axios' 13export default { 14 async asyncData({ $config }) { 15 const { data } = await axios.get(`${$config.apiUrl}/blog`, { 16 headers: { 'X-API-KEY': $config.apiKey }, 17 }) 18 return { 19 items: data.contents, 20 } 21 }, 22としてます。npm run devではエラーもでないのですが、 23Netlifyでデプロイすると以下のようなログとなります。 24 25どうしたらいいでしょうか? 26 279:08:10 PM: $ npm run generate 289:08:10 PM: > ESSENTIAL@1.0.0 generate /opt/build/repo 299:08:10 PM: > nuxt generate 309:09:05 PM: [error] /blog 319:09:05 PM: 329:09:05 PM: TypeError [ERR_HTTP_INVALID_HEADER_VALUE]: Invalid value "undefined" for header "X-API-KEY" 339:09:05 PM: at ClientRequest.setHeader (_http_outgoing.js:521:3) 349:09:05 PM: at new ClientRequest (_http_client.js:241:14) 359:09:05 PM: at Object.request (http.js:46:10) 369:09:05 PM: at RedirectableRequest._performRequest (/opt/build/repo/node_modules/follow-redirects/index.js:265:24) 379:09:05 PM: at new RedirectableRequest (/opt/build/repo/node_modules/follow-redirects/index.js:61:8) 389:09:05 PM: at Object.request (/opt/build/repo/node_modules/follow-redirects/index.js:456:14) 399:09:05 PM: at dispatchHttpRequest (/opt/build/repo/node_modules/axios/lib/adapters/http.js:195:25) 409:09:05 PM: at new Promise (<anonymous>) 419:09:05 PM: at httpAdapter (/opt/build/repo/node_modules/axios/lib/adapters/http.js:46:10) 429:09:05 PM: at dispatchRequest (/opt/build/repo/node_modules/axios/lib/core/dispatchRequest.js:52:10) 439:09:05 PM: at runNextTicks (internal/process/task_queues.js:62:5) 449:09:05 PM: at listOnTimeout (internal/timers.js:518:9) 459:09:05 PM: at processTimers (internal/timers.js:492:7) 469:09:05 PM: at async asyncData (pages/blog/index.vue:33:0) 479:09:05 PM: [error] Invalid value "undefined" for header "X-API-KEY" 489:09:05 PM: at ClientRequest.setHeader (_http_outgoing.js:521:3) 499:09:05 PM: at new ClientRequest (_http_client.js:241:14) 509:09:05 PM: at Object.request (http.js:46:10) 519:09:05 PM: at RedirectableRequest._performRequest (node_modules/follow-redirects/index.js:265:24) 529:09:05 PM: at new RedirectableRequest (node_modules/follow-redirects/index.js:61:8) 539:09:05 PM: at Object.request (node_modules/follow-redirects/index.js:456:14) 549:09:05 PM: at dispatchHttpRequest (node_modules/axios/lib/adapters/http.js:195:25) 559:09:05 PM: at new Promise (<anonymous>) 569:09:05 PM: at httpAdapter (node_modules/axios/lib/adapters/http.js:46:10) 579:09:05 PM: at dispatchRequest (node_modules/axios/lib/core/dispatchRequest.js:52:10) 589:09:05 PM: at runNextTicks (internal/process/task_queues.js:62:5) 599:09:05 PM: at listOnTimeout (internal/timers.js:518:9) 609:09:05 PM: at processTimers (internal/timers.js:492:7) 619:09:05 PM: at async asyncData (pages/blog/index.vue:33:0) 629:09:07 PM: 639:09:07 PM: (build.command completed in 57.1s)
あなたの回答
tips
プレビュー