DEVLOG

Next.js ํ”„๋กœ์ ํŠธ :: ๋ฐฐํฌ(gh-pages, netlify, vercel) ๋ณธ๋ฌธ

frontend/next.js

Next.js ํ”„๋กœ์ ํŠธ :: ๋ฐฐํฌ(gh-pages, netlify, vercel)

meroriiDev 2023. 7. 12. 10:08
728x90
๋ฐ˜์‘ํ˜•
๐Ÿ“–  ๋ชฉ์ฐจ

     

    ์ด๋ฆ„ํ•˜์•ผ next.js ๋ฐฐํฌ ์‚ฝ์งˆ ๊ธฐ๋ก,,,,,๐Ÿ˜‚
    ๊ฒฐ๋ก ์ ์œผ๋กœ๋Š” vercel์„ ์ด์šฉํ•˜์—ฌ ๋ฐฐํฌ๋ฅผ ์ง„ํ–‰ํ–ˆ์Šต๋‹ˆ๋‹ค!

    ๐ŸŽˆ gh-pages

    gh-pages ๋ฐฐํฌ ์ฐธ๊ณ 
    ๊ทธ๋™์•ˆ ๋ชจ๋“  ํ”„๋กœ์ ํŠธ๋ฅผ ๋ฐฐํฌํ• ๋•Œ์—๋Š” ๊ฐ„๋‹จํ•˜๊ฒŒ gh-pages๋ฅผ ์ด์šฉํ–ˆ์—ˆ๋‹ค.
    ๊ทธ๋ž˜์„œ ์ด๋ฒˆ ํ”„๋กœ์ ํŠธ๋„ ๊ธฐ์กด์— ํ–ˆ๋˜ ๊ฒƒ ์ฒ˜๋Ÿผ gh-pages๋ฅผ ์ด์šฉํ•˜์—ฌ ๋ฐฐํฌํ•˜๋ ค๊ณ  ํ–ˆ์œผ๋‚˜,, ์˜ˆ์ƒํ•˜์ง€ ๋ชปํ•œ ๋ฌธ์ œ๋ฅผ ๋งŒ๋‚ฌ๋‹ค.

    ์˜ค๋ฅ˜ : gssp(getServerSideProps) + export

        "build": "next build && next export",

    gh-pages๋กœ ๋ฐฐํฌํ•˜๊ธฐ ์œ„ํ•ด์„œ๋Š” next export ๋ช…๋ น์–ด๋ฅผ ํ†ตํ•ด outํด๋”๋ฅผ ์ƒ์„ฑํ•ด๋‚ด์•ผ ํ•˜๋Š”๋ฐ export ์ง„ํ–‰ ์‹œ ์•„๋ž˜์™€ ๊ฐ™์€ ์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ•œ๋‹ค.

    Error occurred prerendering page "/contents/[id]". Read more: https://nextjs.org/docs/messages/prerender-error
    Error: Error for page /contents/[id]: pages with `getServerSideProps` can not be exported. See more info here: https://nextjs.org/docs/messages/gssp-export
        at C:\Users\SONIA\Desktop\project\meroriiving\node_modules\next\dist\export\worker.js:245:23
        at async Span.traceAsyncFn (C:\Users\SONIA\Desktop\project\meroriiving\node_modules\next\dist\trace\trace.js:79:20)

     

    ๋ฌธ์ œ๋Š” getServerSideProps๋ฅผ ์‚ฌ์šฉํ–ˆ๋‹ค๋Š” ๊ฒƒ.

    ๊ฐ„๋‹จํ•œ ์ •์ ํŽ˜์ด์ง€๊ฐ€ ์•„๋‹ˆ๋ผ ์„œ๋ฒ„์‚ฌ์ด๋“œ๋ Œ๋”๋ง์ด ์ด๋ฃจ์–ด์ง€๋Š” ํŽ˜์ด์ง€์˜ ๊ฒฝ์šฐ export๋ฅผ ์ง€์›ํ•˜์ง€ ์•Š๋Š”๋‹ค๋Š” ๊ฒƒ์ด๋‹ค.

    ๊ณต์‹๋ฌธ์„œ(ggsp์˜ค๋ฅ˜ ๊ด€๋ จ next.js ๊ณต์‹ํ™ˆํŽ˜์ด์ง€ ๊ธ€) ์— ๋”ฐ๋ผ ๋‹ค์Œ ํ•ด๊ฒฐ๋ฐฉ๋ฒ• ๋‘๊ฐ€์ง€๋ฅผ ์–ป์—ˆ์ง€๋งŒ ๋‘ ํ•ด๊ฒฐ๋ฐฉ๋ฒ• ๋ชจ๋‘ ๋ฌธ์ œ๋ฅผ ํ•ด๊ฒฐํ•  ์ˆ˜ ์—†์—ˆ๋‹ค.

    Possible Ways to Fix It

    1. If you'd like to keep your application static, you can use getStaticProps instead of getServerSideProps.
    2. If you want to use server-side rendering, update your build command and remove next export. For example, in your package.json:



    ๐ŸŽˆ netlify

    netlify ๋ฐฐํฌ ์ฐธ๊ณ 

    ํ•ด๊ฒฐ๋ฐฉ๋ฒ•์„ ์ฐพ์•„ ๊ตฌ๊ธ€๋ง์„ ํ•˜๋˜ ์ค‘ netlify๋Š” ์ด๋Ÿฌํ•œ ์ด์Šˆ๋ฅผ ํ•ด๊ฒฐํ•  ์ˆ˜ ์žˆ๋Š” ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ(@netlify/plugin-nextjs)๋ฅผ ์ œ๊ณตํ•œ๋‹ค๋Š” ๊ฒƒ์„ ํ™•์ธํ–ˆ๊ณ , ๊ทธ๋ž˜์„œ gh-pages๊ฐ€ ์•„๋‹Œ ์ƒˆ๋กœ์šด ๋ฐฐํฌํ™˜๊ฒฝ์„ ์ฐพ์•„ ์‹œ๋„ํ•ด๋ณด๋Š” ๊ฒฝํ—˜์„ ํ–ˆ๋‹ค.

    1. @netlify/plugin-nextjs ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ์ถ”๊ฐ€
    2. netlify.toml ํŒŒ์ผ ์ถ”๊ฐ€
    3. package.json์— next export script ์ œ๊ฑฐ
    yarn add @netlify/plugin-nextjs

    ์˜ค๋ฅ˜ : 500 error

    ๋ธ”๋กœ๊ทธ์—์„œ ํ•˜๋ผ๋Š” ๋Œ€๋กœ ์„ธํŒ…ํ•˜๊ณ  publish directory๋„ .next๋กœ ์„ค์ •ํ•ด์ฃผ์—ˆ๋Š”๋ฐ ์•„๋ฌด๋ฆฌํ•ด๋„ ๋งํฌ์— ์ ‘์†์‹œ 500์—๋Ÿฌ๋งŒ์ด ๋‚  ๋งž์ดํ•ด์ฃผ์—ˆ๋‹ค... ํ•ด๊ฒฐ ๋ถˆ๊ฐ€๋Šฅํ•˜๋‹ค๊ณ  ํŒ๋‹จํ•˜์—ฌ ๋น ๋ฅด๊ฒŒ ํฌ๊ธฐ!

    ๐ŸŽˆ vercel

    ๊ทธ๋ž˜์„œ ๋งˆ์ง€๋ง‰์œผ๋กœ ์„ ํƒํ•œ vercel!!

    vercel์€ next.js๋ฅผ ๋งŒ๋“  ์‚ฌ๋žŒ๋“ค์ด ๋ชจ์—ฌ ๋งŒ๋“  ๋นŒ๋“œ+๋ฐฐํฌ+ํ˜ธ์ŠคํŒ… ์„œ๋น„์Šค๋กœ next.js์— ๊ณต์‹์ ์œผ๋กœ ์‚ฌ์šฉํ•˜๊ธธ ์ถ”์ฒœ๋˜๋Š” ํ˜ธ์ŠคํŒ… ์‚ฌ์ดํŠธ์ด๋‹ค.
    ํ•œ๋ฒˆ๋„ ์‚ฌ์šฉํ•ด๋ณด์ง€ ์•Š์•˜๋‹ค๋Š” ์ด์œ ๋กœ ๋ฌด์‹œํ•œ์ฑ„ ์ต์ˆ™ํ–ˆ๋˜ gh-pages๋ฅผ ์ด์šฉํ•ด์™”๋Š”๋ฐ ์ด๋ฒˆ ๊ธฐํšŒ๋ฅผ ํ†ตํ•ด ์ด์šฉํ•ด๋ณด๊ฒŒ ๋๋‹ค!
    ์ œ๋ฐœ.. ๊ณต์‹์œผ๋กœ ์ง€์›๋˜๋Š” ๋งŒํผ ๋˜๊ธธ ๋ฐ”๋ผ๋ฉด์„œ,,!!!

    vercel ๋ฐฐํฌ ์ฐธ๊ณ 

    ์œ„ ๋ธ”๋กœ๊ทธ์—์„œ ํ•˜๋ผ๋Š” ๋Œ€๋กœ ๋ ˆํฌ์ง€ํ† ๋ฆฌ๋ฅผ ์—ฐ๊ฒฐํ›„ ํŽ˜์ด์ง€์—์„œ deploy๋ฅผ ์ง„ํ–‰ํ–ˆ๊ณ , ์ดํ›„ vscodeํ„ฐ๋ฏธ๋„์—์„œ ๋ณ„๋‹ค๋ฅธ build๋‚˜ export๋ฅผ ์ง„ํ–‰ํ•˜์ง€ ์•Š๊ณ  ์ฝ”๋“œ๋ฅผ push ํ•˜๋Š”๊ฒƒ๋งŒ์œผ๋กœ๋„ ์ž๋™๋ฐฐํฌ๊ฐ€ ์—ฐ๊ฒฐ๋˜์–ด ์„ฑ๊ณต์ ์œผ๋กœ ๋ฐฐํฌ๊ฐ€ ์ง„ํ–‰๋˜๋Š” ๊ฒฐ๊ณผ๋ฅผ ์–ป์—ˆ๋‹ค!!! ใ… ใ… ใ… ใ… ใ… ใ… ใ… ใ… ใ… ใ… ใ… ใ… ใ… ใ… ใ… 
    ์•ž์œผ๋กœ๋Š” nextํ”„๋กœ์ ํŠธ๋ฅผ ํ• ๋•Œ vercel์„ ์ ๊ทน ์ด์šฉํ•  ์˜ˆ์ •์ด๋‹ค!โœจโœจ

    ์„ฑ๊ณต!

     

    ๐Ÿ‘‰ Next?

    ํŽ˜์ด์ง€ ๋ฐฐํฌ๊นŒ์ง€ ํ”„๋กœ์ ํŠธ๋ฅผ ๋งˆ๋ฌด๋ฆฌํ–ˆ๋‹ค! ์ดํ›„์—๋Š” ์ฝ”๋“œ๋ฆฌํŒฉํ† ๋ง์„ ๊ฑฐ์ณ ๋” ๊น”๋”ํ•˜๊ณ  ๋ณด๊ธฐ ์ข‹์€ ์ฝ”๋“œ๋ฅผ ๋งŒ๋“œ๋Š”๋ฐ์— ์‹œ๊ฐ„์„ ํˆฌ์žํ•  ์˜ˆ์ •์ด๊ณ , ์‹œ๊ฐ„์ด ๋œ๋‹ค๋ฉด ์˜์ƒ์žฌ์ƒ๊ธฐ๋Šฅ์„ ์ถ”๊ฐ€ํ•  ์˜ˆ์ •์ด๋‹ค!

    728x90
    ๋ฐ˜์‘ํ˜•
    Comments