2 글 보임 - 1 에서 2 까지 (총 2 중에서)
-
글쓴이글
-
2023년 11월 29일 17:31 #105448
김수현참가자선생님, 안녕하세요. 배포하기 위해 npm run build를 했는데, 다음과 같은 에러가 발생했어요. npm run dev 상태에서는 별 이상이 없이 잘 작동됐어요. 아래는 vscode 터미널에서 발생한 에러코드예요.
========================================= npm run build
> forum@0.1.0 build > next build
▲ Next.js 14.0.1 - Environments: .env.local
Failed to compile.
./app/gameScreen/page.js Module not found: Can't resolve './Comment'
https://nextjs.org/docs/messages/module-not-found
./pages/api/post/image_bk.js Error: × the name `default` is exported multiple times ╭─[C:\next_beta\forum\pages\api\post\image_bk.js:1:1] 1 │ import aws from 'aws-sdk' 2 │ ╭─▶ export default async function handler(요청, 응답) { 3 │ │ aws.config.update({ 4 │ │ accessKeyId: process.env.ACCESS_KEY, 5 │ │ secretAccessKey: process.env.SECRET_KEY, 6 │ │ region: 'ap-northeast-2', 7 │ │ signatureVersion: 'v4', 8 │ │ }) 9 │ │ 10 │ │ const s3 = new aws.S3(); 11 │ │ const url = await s3.createPresignedPost({ 12 │ │ Bucket: process.env.BUCKET_NAME, 13 │ │ Fields: { key: 요청.query.file }, 14 │ │ Expires: 60, // seconds 15 │ │ Conditions: [ 16 │ │ ['content-length-range', 0, 1048576], //파일용량 1MB 까지 제한 17 │ │ ], 18 │ │ }) 19 │ │ 20 │ │ 응답.status(200).json(url) 21 │ ├─▶ } · ╰──── previous exported here 22 │ 23 │ 24 │ //======================== 25 │ 'use client' 26 │ import { connectDB } from "@/util/database"; 27 │ import { ObjectId } from "mongodb"; 28 │ import { useState } from "react"; 29 │ 30 │ ╭─▶ export default async function Edit(props) { 31 │ │ const db = (await connectDB).db('forum') 32 │ │ let result = await db.collection('post').findOne({ _id: new ObjectId(props.params.id) }) 33 │ │ 34 │ │ // state for new image source 35 │ │ const [src, setSrc] = useState(result.image); 36 │ │ 37 │ │ return ( 38 │ │ <div className="p-20"> 39 │ │ <h4>글수정</h4> 40 │ │ <form action="/api/post/edit" method="POST"> 41 │ │ <input name="title" defaultValue={result.title} /> 42 │ │ <input name="content" defaultValue={result.content} /> 43 │ │ <input style={{ display: 'none' }} name="_id" defaultValue={result._id.toString()} /> 44 │ │ <input type="hidden" name="image" defaultValue={result.image} /> 45 │ │ <input type="file" accept="image/*" onChange={ 46 │ │ async (e) => { 47 │ │ let file = e.target.files[0]; 48 │ │ if (!file) { // 파일이 선택되지 않았다면 함수를 종료 49 │ │ console.log('파일을 선택해주세요.'); 50 │ │ return; 51 │ │ } 52 │ │ let fname = encodeURIComponent(file.name); 53 │ │ let timestamp = Date.now(); 54 │ │ let filename = timestamp + '_' + fname; 55 │ │ let res = await fetch('/api/post/image?file=' + filename); 56 │ │ res = await res.json(); 57 │ │ console.log(res); 58 │ │ 59 │ │ //S3 업로드 60 │ │ const formData = new FormData(); 61 │ │ Object.entries({ ...res.fields, file }).forEach(([key, value]) => { 62 │ │ formData.append(key, value); 63 │ │ }); 64 │ │ let 업로드결과 = await fetch(res.url, { 65 │ │ method: 'POST', 66 │ │ body: formData, 67 │ │ }); 68 │ │ console.log(업로드결과); 69 │ │ 70 │ │ if (업로드결과.ok) { 71 │ │ let imageURL = 업로드결과.url + '/' + filename; 72 │ │ setSrc(imageURL); 73 │ │ document.querySelector('input[name="image"]').value = imageURL; // 폼 데이터에 이미지 URL 추가 74 │ │ } else { 75 │ │ console.log('실패'); 76 │ │ } 77 │ │ } 78 │ │ } /> 79 │ │ < img src={src} /> 80 │ │ <button type="submit">전송</button> 81 │ │ </form> 82 │ │ </div> 83 │ │ ); 84 │ ├─▶ } · ╰──── exported more than once ╰────
Error: ☞ Exported identifiers must be unique
Import trace for requested module: ./pages/api/post/image_bk.js
> Build failed because of webpack errors Creating an optimized production build .
-
글쓴이글
2 글 보임 - 1 에서 2 까지 (총 2 중에서)
- 답변은 로그인 후 가능합니다.