Commit ebb6a303 authored by Tim Neutkens's avatar Tim Neutkens

Revert "Add warning during `next build` when sharp is missing (#27933)"

This reverts commit 51a2a028.
parent 52486cec
...@@ -930,22 +930,6 @@ export default async function build( ...@@ -930,22 +930,6 @@ export default async function build(
return returnValue return returnValue
}) })
if (isNextImageImported) {
try {
if (process.env.NEXT_SHARP_PATH) {
require(process.env.NEXT_SHARP_PATH)
} else {
require.resolve('sharp', {
paths: [path.join(dir, 'node_modules')],
})
}
} catch (e) {
Log.warn(
'Detected `next/image` usage without `sharp`. https://nextjs.org/docs/messages/sharp-missing-in-production'
)
}
}
if (customAppGetInitialProps) { if (customAppGetInitialProps) {
console.warn( console.warn(
chalk.bold.yellow(`Warning: `) + chalk.bold.yellow(`Warning: `) +
......
...@@ -23,11 +23,10 @@ const imagesDir = join(appDir, '.next', 'cache', 'images') ...@@ -23,11 +23,10 @@ const imagesDir = join(appDir, '.next', 'cache', 'images')
const nextConfig = new File(join(appDir, 'next.config.js')) const nextConfig = new File(join(appDir, 'next.config.js'))
const largeSize = 1080 // defaults defined in server/config.ts const largeSize = 1080 // defaults defined in server/config.ts
let nextOutput let nextOutput
let buildOutput
let appPort let appPort
let app let app
const sharpRuntimeWarning = `For production Image Optimization with Next.js, the optional 'sharp' package is strongly recommended`
const sharpBuildWarning = 'Detected `next/image` usage without `sharp`.' const sharpMissingText = `For production Image Optimization with Next.js, the optional 'sharp' package is strongly recommended`
async function fsToJson(dir, output = {}) { async function fsToJson(dir, output = {}) {
const files = await fs.readdir(dir) const files = await fs.readdir(dir)
...@@ -727,29 +726,13 @@ function runTests({ w, isDev, domains = [], ttl, isSharp }) { ...@@ -727,29 +726,13 @@ function runTests({ w, isDev, domains = [], ttl, isSharp }) {
expect(Object.keys(json1).length).toBe(1) expect(Object.keys(json1).length).toBe(1)
}) })
if (isDev) { if (isDev || isSharp) {
it('should not have runtime warning in dev', () => { it('should not have sharp missing warning', () => {
expect(nextOutput).not.toContain(sharpRuntimeWarning) expect(nextOutput).not.toContain(sharpMissingText)
})
it('should not have build warning in dev', () => {
expect(buildOutput).not.toContain(sharpBuildWarning)
})
} else if (isSharp) {
it('should not have runtime warning when sharp is installed', () => {
expect(nextOutput).not.toContain(sharpRuntimeWarning)
})
it('should not have build warning when sharp is installed', () => {
expect(buildOutput).not.toContain(sharpBuildWarning)
}) })
} else { } else {
it('should have runtime warning when sharp is not installed', () => { it('should have sharp missing warning', () => {
expect(nextOutput).toContain(sharpRuntimeWarning) expect(nextOutput).toContain(sharpMissingText)
})
it('should have build warning when sharp is not installed', () => {
expect(buildOutput).toContain(sharpBuildWarning)
}) })
} }
} }
...@@ -927,10 +910,8 @@ describe('Image Optimizer', () => { ...@@ -927,10 +910,8 @@ describe('Image Optimizer', () => {
}, },
}) })
nextOutput = '' nextOutput = ''
buildOutput = ''
nextConfig.replace('{ /* replaceme */ }', json) nextConfig.replace('{ /* replaceme */ }', json)
const out = await nextBuild(appDir, [], { stderr: true }) await nextBuild(appDir)
buildOutput = out.stderr
appPort = await findPort() appPort = await findPort()
app = await nextStart(appDir, appPort, { app = await nextStart(appDir, appPort, {
onStderr(msg) { onStderr(msg) {
...@@ -968,8 +949,7 @@ describe('Image Optimizer', () => { ...@@ -968,8 +949,7 @@ describe('Image Optimizer', () => {
}, },
}` }`
) )
const out = await nextBuild(appDir, [], { stderr: true }) await nextBuild(appDir)
buildOutput = out.stderr
appPort = await findPort() appPort = await findPort()
app = await nextStart(appDir, appPort) app = await nextStart(appDir, appPort)
}) })
...@@ -1045,8 +1025,7 @@ describe('Image Optimizer', () => { ...@@ -1045,8 +1025,7 @@ describe('Image Optimizer', () => {
}, },
}` }`
nextConfig.replace('{ /* replaceme */ }', newConfig) nextConfig.replace('{ /* replaceme */ }', newConfig)
const out = await nextBuild(appDir, [], { stderr: true }) await nextBuild(appDir)
buildOutput = out.stderr
appPort = await findPort() appPort = await findPort()
app = await nextStart(appDir, appPort) app = await nextStart(appDir, appPort)
}) })
...@@ -1105,7 +1084,6 @@ describe('Image Optimizer', () => { ...@@ -1105,7 +1084,6 @@ describe('Image Optimizer', () => {
const size = 384 // defaults defined in server/config.ts const size = 384 // defaults defined in server/config.ts
beforeAll(async () => { beforeAll(async () => {
nextOutput = '' nextOutput = ''
buildOutput = ''
appPort = await findPort() appPort = await findPort()
app = await launchApp(appDir, appPort, { app = await launchApp(appDir, appPort, {
onStderr(msg) { onStderr(msg) {
...@@ -1133,7 +1111,6 @@ describe('Image Optimizer', () => { ...@@ -1133,7 +1111,6 @@ describe('Image Optimizer', () => {
}, },
}) })
nextOutput = '' nextOutput = ''
buildOutput = ''
nextConfig.replace('{ /* replaceme */ }', json) nextConfig.replace('{ /* replaceme */ }', json)
appPort = await findPort() appPort = await findPort()
app = await launchApp(appDir, appPort, { app = await launchApp(appDir, appPort, {
...@@ -1156,9 +1133,7 @@ describe('Image Optimizer', () => { ...@@ -1156,9 +1133,7 @@ describe('Image Optimizer', () => {
const size = 384 // defaults defined in server/config.ts const size = 384 // defaults defined in server/config.ts
beforeAll(async () => { beforeAll(async () => {
nextOutput = '' nextOutput = ''
buildOutput = '' await nextBuild(appDir)
const out = await nextBuild(appDir, [], { stderr: true })
buildOutput = out.stderr
appPort = await findPort() appPort = await findPort()
app = await nextStart(appDir, appPort, { app = await nextStart(appDir, appPort, {
onStderr(msg) { onStderr(msg) {
...@@ -1192,10 +1167,8 @@ describe('Image Optimizer', () => { ...@@ -1192,10 +1167,8 @@ describe('Image Optimizer', () => {
}, },
}) })
nextOutput = '' nextOutput = ''
buildOutput = ''
nextConfig.replace('{ /* replaceme */ }', json) nextConfig.replace('{ /* replaceme */ }', json)
const out = await nextBuild(appDir, [], { stderr: true }) await nextBuild(appDir)
buildOutput = out.stderr
appPort = await findPort() appPort = await findPort()
app = await nextStart(appDir, appPort, { app = await nextStart(appDir, appPort, {
onStderr(msg) { onStderr(msg) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment