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

next/image failed to use the custom loader when using next dev --turbo #60097

Closed
1 task done
mhughdo opened this issue Jan 2, 2024 · 3 comments · Fixed by #60736
Closed
1 task done

next/image failed to use the custom loader when using next dev --turbo #60097

mhughdo opened this issue Jan 2, 2024 · 3 comments · Fixed by #60736
Labels
bug Issue was opened via the bug report template. Image (next/image) Related to Next.js Image Optimization. linear: turbopack Confirmed issue that is tracked by the Turbopack team. locked Turbopack Related to Turbopack with Next.js.

Comments

@mhughdo
Copy link
Contributor

mhughdo commented Jan 2, 2024

Link to the code that reproduces this issue

https://github.com/mhughdo/nextjs-bug-reproduction-app

To Reproduce

Run pnpm dev

Current vs. Expected behavior

Current:

  • Next is showing the missing loader prop error when using the custom loader
image Expected behavior: - The image could be loaded properly

Verify canary release

  • I verified that the issue exists in the latest Next.js canary release

Provide environment information

Operating System:
 Arch: arm64
 Platform: darwin
 Version: Darwin Kernel Version 23.0.0
Binaries:
 node: v20.8.0
 pnpm: 8.13.1
Packages
 next: Next.js 14.0.5-canary.34 (turbo)
 react: 18.2.0
 react-dom: 18.2.0

Which area(s) are affected? (Select all that apply)

Image optimization (next/image, next/legacy/image), Turbopack (--turbo)

Additional context

No response

PACK-2190

@mhughdo mhughdo added the bug Issue was opened via the bug report template. label Jan 2, 2024
@github-actions github-actions bot added Image (next/image) Related to Next.js Image Optimization. Turbopack Related to Turbopack with Next.js. labels Jan 2, 2024
@Bahlaouane-Hamza
Copy link

Bahlaouane-Hamza commented Jan 2, 2024

I can confirm, i think this is related to 946c9c5

This introduce

// @ts-ignore - This is replaced by webpack alias
import defaultLoader from 'next/dist/shared/lib/image-loader'

Which is supposed to replaced by Webpack here
https://github.com/vercel/next.js/blob/canary/packages/next/src/build/create-compiler-aliases.ts#L114

I believe the equivalent webpack aliasing mecanic for Turbo is here https://github.com/vercel/next.js/blob/canary/packages/next-swc/crates/next-core/src/next_import_map.rs, but this does not contain any ref to image-loader

You can manage the aliasing yourself in the meantime using experimental.turbo.resolveAlias like so:

diff --git a/next.config.js b/next.config.js
index 897e72e..63c4d84 100644
--- a/next.config.js
+++ b/next.config.js
@@ -14,6 +14,13 @@ const nextConfig = {
     path: 'https://hughdo-dev.imgix.net/',
     loaderFile: './loader/index.ts',
   },
+  experimental: {
+    turbo: {
+      resolveAlias: {
+        "next/dist/shared/lib/image-loader": './loader/index.ts',
+      },
+    },
+  },
 }

 module.exports = nextConfig

@styfle any guidance on this please ?

@mhughdo
Copy link
Contributor Author

mhughdo commented Jan 4, 2024

@Bahlaouane-Hamza

Thank you for your solution. I can confirm that it fixed the problem for now.

@kdy1 kdy1 added the linear: turbopack Confirmed issue that is tracked by the Turbopack team. label Jan 4, 2024
ForsakenHarmony added a commit that referenced this issue Jan 18, 2024
### What?
We were missing the alias (and config field) for custom image loaders.

Closes PACK-2190
Fixes #60097
Copy link
Contributor

github-actions bot commented Feb 2, 2024

This closed issue has been automatically locked because it had no new activity for 2 weeks. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@github-actions github-actions bot added the locked label Feb 2, 2024
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 2, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue was opened via the bug report template. Image (next/image) Related to Next.js Image Optimization. linear: turbopack Confirmed issue that is tracked by the Turbopack team. locked Turbopack Related to Turbopack with Next.js.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants