Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: show the error message if images.loaderFile doesn't export a default function #64036

Merged
merged 21 commits into from
Apr 10, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
04eaa77
feat: show the concrete error message if the loader file don't export…
ojj1123 Apr 3, 2024
259fddc
Merge branch 'canary' into fix/custom-loader-config
ojj1123 Apr 3, 2024
732940d
Merge branch 'canary' into fix/custom-loader-config
styfle Apr 3, 2024
fabbe3e
Merge branch 'canary' into fix/custom-loader-config
ojj1123 Apr 4, 2024
c272734
test: loader file named export error
ojj1123 Apr 4, 2024
45432bb
fix: check defaultLoader only in getImgProps
ojj1123 Apr 4, 2024
90d5bd5
test: getImageProps
ojj1123 Apr 4, 2024
135be5f
Merge branch 'canary' into fix/custom-loader-config
ojj1123 Apr 4, 2024
93548e7
revert __NEXT_IMAGE_OPTS
ojj1123 Apr 5, 2024
385345a
add test case
ojj1123 Apr 5, 2024
f10b06d
Merge branch 'canary' into fix/custom-loader-config
ojj1123 Apr 5, 2024
80b8f13
Merge branch 'canary' into fix/custom-loader-config
ojj1123 Apr 7, 2024
fce6313
Merge branch 'canary' into fix/custom-loader-config
ojj1123 Apr 8, 2024
51026fc
Merge branch 'canary' into fix/custom-loader-config
ojj1123 Apr 8, 2024
fc1a35e
Merge branch 'canary' into fix/custom-loader-config
ojj1123 Apr 9, 2024
5f8b8bf
Merge branch 'canary' into fix/custom-loader-config
ojj1123 Apr 9, 2024
9099e78
fix: add next-start test suite
ojj1123 Apr 10, 2024
82eeab4
skip test if build turbopack
ojj1123 Apr 10, 2024
2a2dcaf
Merge branch 'canary' into fix/custom-loader-config
ojj1123 Apr 10, 2024
1e1c694
Apply suggestions from code review
styfle Apr 10, 2024
cda86fc
Apply suggestions from code review
styfle Apr 10, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ function getImageConfig(
imageSizes: config.images.imageSizes,
path: config.images.path,
loader: config.images.loader,
loaderFile: config.images.loaderFile,
ojj1123 marked this conversation as resolved.
Show resolved Hide resolved
dangerouslyAllowSVG: config.images.dangerouslyAllowSVG,
unoptimized: config?.images?.unoptimized,
...(dev
Expand Down
5 changes: 5 additions & 0 deletions packages/next/src/client/image-component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,11 @@ export const Image = forwardRef<HTMLImageElement | null, ImageProps>(
const [blurComplete, setBlurComplete] = useState(false)
const [showAltText, setShowAltText] = useState(false)

if (config.loaderFile && typeof defaultLoader === 'undefined') {
throw new Error(
'The loader file must export a default function that returns a string.\nSee more info here: https://nextjs.org/docs/messages/invalid-images-config'
)
}
const { props: imgAttributes, meta: imgMeta } = getImgProps(props, {
defaultLoader,
imgConf: config,
Expand Down
10 changes: 8 additions & 2 deletions packages/next/src/shared/lib/image-external.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,16 @@ import defaultLoader from 'next/dist/shared/lib/image-loader'
* Read more: [Next.js docs: `getImageProps`](https://nextjs.org/docs/app/api-reference/components/image#getimageprops)
*/
export function getImageProps(imgProps: ImageProps) {
// This is replaced by webpack define plugin
const config = process.env.__NEXT_IMAGE_OPTS as any as ImageConfigComplete
if (config.loaderFile && typeof defaultLoader === 'undefined') {
throw new Error(
'The loader file must export a default function that returns a string.\nSee more info here: https://nextjs.org/docs/messages/invalid-images-config'
)
}
const { props } = getImgProps(imgProps, {
defaultLoader,
// This is replaced by webpack define plugin
imgConf: process.env.__NEXT_IMAGE_OPTS as any as ImageConfigComplete,
imgConf: config,
})
// Normally we don't care about undefined props because we pass to JSX,
// but this exported function could be used by the end user for anything
Expand Down