Skip to content

Commit ebb6a30

Browse files
committed
Revert "Add warning during next build when sharp is missing (#27933)"
This reverts commit 51a2a02.
1 parent 52486ce commit ebb6a30

File tree

2 files changed

+12
-55
lines changed

2 files changed

+12
-55
lines changed

packages/next/build/index.ts

-16
Original file line numberDiff line numberDiff line change
@@ -930,22 +930,6 @@ export default async function build(
930930
return returnValue
931931
})
932932

933-
if (isNextImageImported) {
934-
try {
935-
if (process.env.NEXT_SHARP_PATH) {
936-
require(process.env.NEXT_SHARP_PATH)
937-
} else {
938-
require.resolve('sharp', {
939-
paths: [path.join(dir, 'node_modules')],
940-
})
941-
}
942-
} catch (e) {
943-
Log.warn(
944-
'Detected `next/image` usage without `sharp`. https://nextjs.org/docs/messages/sharp-missing-in-production'
945-
)
946-
}
947-
}
948-
949933
if (customAppGetInitialProps) {
950934
console.warn(
951935
chalk.bold.yellow(`Warning: `) +

test/integration/image-optimizer/test/index.test.js

+12-39
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,10 @@ const imagesDir = join(appDir, '.next', 'cache', 'images')
2323
const nextConfig = new File(join(appDir, 'next.config.js'))
2424
const largeSize = 1080 // defaults defined in server/config.ts
2525
let nextOutput
26-
let buildOutput
2726
let appPort
2827
let app
29-
const sharpRuntimeWarning = `For production Image Optimization with Next.js, the optional 'sharp' package is strongly recommended`
30-
const sharpBuildWarning = 'Detected `next/image` usage without `sharp`.'
28+
29+
const sharpMissingText = `For production Image Optimization with Next.js, the optional 'sharp' package is strongly recommended`
3130

3231
async function fsToJson(dir, output = {}) {
3332
const files = await fs.readdir(dir)
@@ -727,29 +726,13 @@ function runTests({ w, isDev, domains = [], ttl, isSharp }) {
727726
expect(Object.keys(json1).length).toBe(1)
728727
})
729728

730-
if (isDev) {
731-
it('should not have runtime warning in dev', () => {
732-
expect(nextOutput).not.toContain(sharpRuntimeWarning)
733-
})
734-
735-
it('should not have build warning in dev', () => {
736-
expect(buildOutput).not.toContain(sharpBuildWarning)
737-
})
738-
} else if (isSharp) {
739-
it('should not have runtime warning when sharp is installed', () => {
740-
expect(nextOutput).not.toContain(sharpRuntimeWarning)
741-
})
742-
743-
it('should not have build warning when sharp is installed', () => {
744-
expect(buildOutput).not.toContain(sharpBuildWarning)
729+
if (isDev || isSharp) {
730+
it('should not have sharp missing warning', () => {
731+
expect(nextOutput).not.toContain(sharpMissingText)
745732
})
746733
} else {
747-
it('should have runtime warning when sharp is not installed', () => {
748-
expect(nextOutput).toContain(sharpRuntimeWarning)
749-
})
750-
751-
it('should have build warning when sharp is not installed', () => {
752-
expect(buildOutput).toContain(sharpBuildWarning)
734+
it('should have sharp missing warning', () => {
735+
expect(nextOutput).toContain(sharpMissingText)
753736
})
754737
}
755738
}
@@ -927,10 +910,8 @@ describe('Image Optimizer', () => {
927910
},
928911
})
929912
nextOutput = ''
930-
buildOutput = ''
931913
nextConfig.replace('{ /* replaceme */ }', json)
932-
const out = await nextBuild(appDir, [], { stderr: true })
933-
buildOutput = out.stderr
914+
await nextBuild(appDir)
934915
appPort = await findPort()
935916
app = await nextStart(appDir, appPort, {
936917
onStderr(msg) {
@@ -968,8 +949,7 @@ describe('Image Optimizer', () => {
968949
},
969950
}`
970951
)
971-
const out = await nextBuild(appDir, [], { stderr: true })
972-
buildOutput = out.stderr
952+
await nextBuild(appDir)
973953
appPort = await findPort()
974954
app = await nextStart(appDir, appPort)
975955
})
@@ -1045,8 +1025,7 @@ describe('Image Optimizer', () => {
10451025
},
10461026
}`
10471027
nextConfig.replace('{ /* replaceme */ }', newConfig)
1048-
const out = await nextBuild(appDir, [], { stderr: true })
1049-
buildOutput = out.stderr
1028+
await nextBuild(appDir)
10501029
appPort = await findPort()
10511030
app = await nextStart(appDir, appPort)
10521031
})
@@ -1105,7 +1084,6 @@ describe('Image Optimizer', () => {
11051084
const size = 384 // defaults defined in server/config.ts
11061085
beforeAll(async () => {
11071086
nextOutput = ''
1108-
buildOutput = ''
11091087
appPort = await findPort()
11101088
app = await launchApp(appDir, appPort, {
11111089
onStderr(msg) {
@@ -1133,7 +1111,6 @@ describe('Image Optimizer', () => {
11331111
},
11341112
})
11351113
nextOutput = ''
1136-
buildOutput = ''
11371114
nextConfig.replace('{ /* replaceme */ }', json)
11381115
appPort = await findPort()
11391116
app = await launchApp(appDir, appPort, {
@@ -1156,9 +1133,7 @@ describe('Image Optimizer', () => {
11561133
const size = 384 // defaults defined in server/config.ts
11571134
beforeAll(async () => {
11581135
nextOutput = ''
1159-
buildOutput = ''
1160-
const out = await nextBuild(appDir, [], { stderr: true })
1161-
buildOutput = out.stderr
1136+
await nextBuild(appDir)
11621137
appPort = await findPort()
11631138
app = await nextStart(appDir, appPort, {
11641139
onStderr(msg) {
@@ -1192,10 +1167,8 @@ describe('Image Optimizer', () => {
11921167
},
11931168
})
11941169
nextOutput = ''
1195-
buildOutput = ''
11961170
nextConfig.replace('{ /* replaceme */ }', json)
1197-
const out = await nextBuild(appDir, [], { stderr: true })
1198-
buildOutput = out.stderr
1171+
await nextBuild(appDir)
11991172
appPort = await findPort()
12001173
app = await nextStart(appDir, appPort, {
12011174
onStderr(msg) {

0 commit comments

Comments
 (0)