다디와 괴발개발

[M1 Mac, AWS Lambda] 'sharp' cannot find module, Something went wrong installing the \"sharp\" 오류 해결 본문

TroubleShooting

[M1 Mac, AWS Lambda] 'sharp' cannot find module, Something went wrong installing the \"sharp\" 오류 해결

아임다디 2022. 4. 26. 21:40

발생시기


이미지를 resize하는 AWS Lambda 함수를 만들기 위해 작업하는 도중 발생한 에러

상황


npm의 sharp모듈을 사용해야 하는데, 모듈을 사용하려고 하면 'sharp' cannot find module이나, Something went wrong installing the \"sharp\" 에러가 출력되는 상황

원인


M1 Mac 문제인 것으로 확인되며, package.jsondepencencies에서 sharp가 있으면 해당 에러를 뱉는다.

해결


 

package.jsondependencies에서 sharp관련 라인을 삭제해준다

{
    "dependencies": {
        "aws-sdk": "^2.1111.0"
          "sharp": "^0.30.3" // 해당 라인을 삭제해준다
    },
    "devDependencies": {
        "jest": "^26.6.3"
    },
    "scripts": {
        "test": "jest",
        "preinstall": "npm install --platform=linux --arch=x64 --no-save sharp"
    }
}

결론


우리 m1이는 왜이렇게 까다로울까. 구글링 할 때도 mac이나 m1을 붙여서 검색하면 좀 더 수월하게 검색할 수 있을 것 같다.