-
Notifications
You must be signed in to change notification settings - Fork 28.9k
Closed
Milestone
Description
Bug report
Describe the bug
Next.js has an optional dependency on sharp. This means that it should run without sharp present in node_modules.
PR #20035 broke this by adding require.resolve('sharp')
without a try/catch to catch MODULE_NOT_FOUND
.
I discovered this because sharp no longer installs with NPM 7 (see #20432).
To Reproduce
npm i next@10.0.4-canary.7
rimraf node_modules/sharp
npm run build
Build error occurred
Error: Cannot find module 'sharp'
Require stack:
- C:\Projects\ANWB\Travelhome-git\camper2-website\node_modules\next\dist\build\index.js
- C:\Projects\ANWB\Travelhome-git\camper2-website\node_modules\next\dist\cli\next-build.js
- C:\Projects\ANWB\Travelhome-git\camper2-website\node_modules\next\dist\bin\next
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:902:15)
at Function.resolve (internal/modules/cjs/helpers.js:94:19)
at build (C:\Projects\ANWB\Travelhome-git\camper2-website\node_modules\next\dist\build\index.js:11:794) {
code: 'MODULE_NOT_FOUND',
requireStack: [
'C:\Projects\ANWB\Travelhome-git\camper2-website\node_modules\next\dist\build\index.js',
'C:\Projects\ANWB\Travelhome-git\camper2-website\node_modules\next\dist\cli\next-build.js',
'C:\Projects\ANWB\Travelhome-git\camper2-website\node_modules\next\dist\bin\next'
]
}
Expected behavior
The site builds OK.
- OS: Windows or Linux (alpine in docker)
- Version of Next.js: 10.0.4-canary.7 and up
- Version of Node.js: 14 (latest)
- Deployment: fails on build
Erazihel, etienne-bondot, SharpMox, lindsaylevine, thien-do and 18 morerobertwbradford, VladSez, tarunama, 1ambda and lukeboi