Error: Command "npm run build" exited with 1

박주홍·2021년 9월 17일
0

Error

목록 보기
5/9

vercel로 react를 배포할때 나타난 오류다.

결론

: 모든 오류,경고 고치니까 정상배포




https://github.com/vercel/next.js/discussions/14416
에서의 말대로

	npm install date-fns --save

을 했지만 여전히 오류가 났다.

https://stackoverflow.com/questions/66840942/vercel-deployment-error-command-npm-run-build-exited-with-1

두번째 참조 링크에서 npm run start로 터미널의 모든 경고가 지워졌는 지를 살펴보라그래서 npm run start로 살펴보았다. 강력한 코드만 배포되도록 하기위해 빌드가 실패된다는 것이다.

콘솔에 에러뜬 하나가

Error while trying to use the following icon from the Manifest: http://localhost:3000/logo192.png (Download error or resource isn't a valid image)

여서 public/manifest.json에서 "icons"을 빈배열로 했다. 그 후 vercel에서 배포를 했는 데,, build에서 좀 되나 싶더니 다시 Error: Command "npm run build" exited with 1..

홍길동 is defiend but is not used 
같은 경고들도 다 지워보도록 하겠다..
  1. export default를 할때 배열은 먼저 변수에 할당을 해주고 export default하라 해서 그렇게 함. (dummyData 였음..)
Assignments to the 'forCleanUp' variable from inside React Hook useEffect will be lost after each render.
To preserve the value over time, store it in a useRef Hook and keep the
mutable value in the '.current' property. Otherwise, you can move this
variabledirectly inside useEffect
let forCleanup = true;
useEffect(()=>{
	if(forCleanup){
    	// ajax요청
    }
  	return ()=>{
    	forCleanup = false;
    }
},[])

ajax요청을 한번만 하도록 이렇게 구현했는데 저런 오류가 떠버려서 검색을 해보니 state로 관리하라는 말이 있어서..

 const [forCleanUp, setForCleanUp] = useState(true);


    useEffect(() => {
        if (forCleanUp) {
            setPictures(picturesUrl);
            // ajax
        }
        return () => {
            setForCleanUp(false);
        }
    }, []);

이렇게 하니깐 오류가 다음과 같이 바뀌었다.

React Hook useEffect has a missing dependency: 'forCleanUp'. Either
include it or remove the dependency array  react-hooks/exhaustive-deps

참고
: https://kyounghwan01.github.io/blog/React/exhaustive-deps-warning/#_1-useeffect%E1%84%82%E1%85%A2-state%E1%84%85%E1%85%B3%E1%86%AF-%E1%84%82%E1%85%A5%E1%87%82%E1%84%8B%E1%85%A5%E1%84%8C%E1%85%AE%E1%86%B7

useEffect내에 사용하고 있는 state를 배열안에 추가시켜달라는 의미라고 한다.

추가하니까 에러는 사라졌는 데 왜 그래야하는 거지 ??

추가공부해야겠다.

profile
고통없는 성장은 없다고 할 수 있겠다....

0개의 댓글