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

Conversation

ojj1123
Copy link
Contributor

@ojj1123 ojj1123 commented Apr 3, 2024

fixes #63803

What I do?

  • If the loader file export the function as named, Next.js throws the error.
  • But this error is a bit confusing for the developers.
  • So I open this PR for showing the accurate error message.

AS-IS / TO-BE

AS-IS

TypeError: Cannot use 'in' operator to search for '__next_img_default' in undefined
스크린샷 2024-03-28 16 10 53

TO-BE

Error: The loader file must export a default function that returns a string.
See more info here: https://nextjs.org/docs/messages/invalid-images-config
스크린샷 2024-03-28 16 10 53

@ijjk ijjk added the type: next label Apr 3, 2024
@ojj1123
Copy link
Contributor Author

ojj1123 commented Apr 3, 2024

Question

Should I write the test code?

@ojj1123 ojj1123 marked this pull request as ready for review April 3, 2024 17:10
@ojj1123 ojj1123 requested review from timeyoutakeit and molebox and removed request for a team April 3, 2024 17:10
@styfle
Copy link
Member

styfle commented Apr 3, 2024

Should I write the test code?

Yes, please add a test to confirm this works as expected

@ijjk
Copy link
Member

ijjk commented Apr 3, 2024

Failing test suites

Commit: cda86fc

__NEXT_EXPERIMENTAL_PPR=true pnpm test-dev test/e2e/app-dir/navigation/navigation.test.ts (PPR)

  • app dir - navigation > navigating to dynamic params & changing the casing > should load the page correctly
Expand output

● app dir - navigation › navigating to dynamic params & changing the casing › should load the page correctly

expect(received).toContain(expected) // indexOf

Expected substring: "[paramB] page"
Received string:    "/paramA/paramB
/paramA/noParam"

  894 |
  895 |         await retry(async () => {
> 896 |           expect(await browser.elementByCss('body').text()).toContain(
      |                                                             ^
  897 |             '[paramB] page'
  898 |           )
  899 |         })

  at toContain (e2e/app-dir/navigation/navigation.test.ts:896:61)
  at retry (lib/next-test-utils.ts:730:14)
  at Object.<anonymous> (e2e/app-dir/navigation/navigation.test.ts:895:9)

Read more about building and testing Next.js in contributing.md.

@ijjk
Copy link
Member

ijjk commented Apr 3, 2024

Stats from current PR

Default Build (Increase detected ⚠️)
General Overall increase ⚠️
vercel/next.js canary ojj1123/next.js fix/custom-loader-config Change
buildDuration 15.7s 15.8s ⚠️ +103ms
buildDurationCached 9.6s 7.1s N/A
nodeModulesSize 199 MB 199 MB ⚠️ +1.09 kB
nextStartRea..uration (ms) 425ms 424ms N/A
Client Bundles (main, webpack)
vercel/next.js canary ojj1123/next.js fix/custom-loader-config Change
2453-HASH.js gzip 31.4 kB 31.4 kB N/A
3304.HASH.js gzip 181 B 181 B
3f784ff6-HASH.js gzip 53.7 kB 53.7 kB
8299-HASH.js gzip 5.05 kB 5.1 kB N/A
framework-HASH.js gzip 45.2 kB 45.2 kB
main-app-HASH.js gzip 242 B 241 B N/A
main-HASH.js gzip 32.2 kB 32.2 kB N/A
webpack-HASH.js gzip 1.68 kB 1.68 kB N/A
Overall change 99 kB 99 kB
Legacy Client Bundles (polyfills)
vercel/next.js canary ojj1123/next.js fix/custom-loader-config Change
polyfills-HASH.js gzip 31 kB 31 kB
Overall change 31 kB 31 kB
Client Pages
vercel/next.js canary ojj1123/next.js fix/custom-loader-config Change
_app-HASH.js gzip 196 B 197 B N/A
_error-HASH.js gzip 184 B 184 B
amp-HASH.js gzip 505 B 505 B
css-HASH.js gzip 324 B 325 B N/A
dynamic-HASH.js gzip 2.5 kB 2.5 kB N/A
edge-ssr-HASH.js gzip 258 B 258 B
head-HASH.js gzip 352 B 352 B
hooks-HASH.js gzip 370 B 371 B N/A
image-HASH.js gzip 4.22 kB 4.27 kB N/A
index-HASH.js gzip 259 B 259 B
link-HASH.js gzip 2.67 kB 2.67 kB N/A
routerDirect..HASH.js gzip 314 B 312 B N/A
script-HASH.js gzip 386 B 386 B
withRouter-HASH.js gzip 309 B 309 B
1afbb74e6ecf..834.css gzip 106 B 106 B
Overall change 2.36 kB 2.36 kB
Client Build Manifests
vercel/next.js canary ojj1123/next.js fix/custom-loader-config Change
_buildManifest.js gzip 483 B 485 B N/A
Overall change 0 B 0 B
Rendered Page Sizes
vercel/next.js canary ojj1123/next.js fix/custom-loader-config Change
index.html gzip 530 B 528 B N/A
link.html gzip 542 B 542 B
withRouter.html gzip 525 B 523 B N/A
Overall change 542 B 542 B
Edge SSR bundle Size
vercel/next.js canary ojj1123/next.js fix/custom-loader-config Change
edge-ssr.js gzip 95.6 kB 95.6 kB N/A
page.js gzip 3.06 kB 3.06 kB N/A
Overall change 0 B 0 B
Middleware size
vercel/next.js canary ojj1123/next.js fix/custom-loader-config Change
middleware-b..fest.js gzip 624 B 623 B N/A
middleware-r..fest.js gzip 155 B 156 B N/A
middleware.js gzip 25.5 kB 25.5 kB N/A
edge-runtime..pack.js gzip 839 B 839 B
Overall change 839 B 839 B
Next Runtimes
vercel/next.js canary ojj1123/next.js fix/custom-loader-config Change
app-page-exp...dev.js gzip 170 kB 170 kB
app-page-exp..prod.js gzip 97.4 kB 97.4 kB
app-page-tur..prod.js gzip 99.1 kB 99.1 kB
app-page-tur..prod.js gzip 93.4 kB 93.4 kB
app-page.run...dev.js gzip 144 kB 144 kB
app-page.run..prod.js gzip 91.9 kB 91.9 kB
app-route-ex...dev.js gzip 21.5 kB 21.5 kB
app-route-ex..prod.js gzip 15.2 kB 15.2 kB
app-route-tu..prod.js gzip 15.2 kB 15.2 kB
app-route-tu..prod.js gzip 14.9 kB 14.9 kB
app-route.ru...dev.js gzip 21.1 kB 21.1 kB
app-route.ru..prod.js gzip 14.9 kB 14.9 kB
pages-api-tu..prod.js gzip 9.55 kB 9.55 kB
pages-api.ru...dev.js gzip 9.82 kB 9.82 kB
pages-api.ru..prod.js gzip 9.55 kB 9.55 kB
pages-turbo...prod.js gzip 22.5 kB 22.5 kB
pages.runtim...dev.js gzip 23.1 kB 23.1 kB
pages.runtim..prod.js gzip 22.5 kB 22.5 kB
server.runti..prod.js gzip 51.3 kB 51.3 kB
Overall change 948 kB 948 kB
build cache Overall increase ⚠️
vercel/next.js canary ojj1123/next.js fix/custom-loader-config Change
0.pack gzip 1.58 MB 1.58 MB N/A
index.pack gzip 106 kB 107 kB ⚠️ +803 B
Overall change 106 kB 107 kB ⚠️ +803 B
Diff details
Diff for middleware.js

Diff too large to display

Diff for image-HASH.js
@@ -1,7 +1,7 @@
 (self["webpackChunk_N_E"] = self["webpackChunk_N_E"] || []).push([
   [8358],
   {
-    /***/ 1552: /***/ function (
+    /***/ 4070: /***/ function (
       __unused_webpack_module,
       __unused_webpack_exports,
       __webpack_require__
@@ -9,7 +9,7 @@
       (window.__NEXT_P = window.__NEXT_P || []).push([
         "/image",
         function () {
-          return __webpack_require__(5237);
+          return __webpack_require__(396);
         },
       ]);
       if (false) {
@@ -18,7 +18,7 @@
       /***/
     },
 
-    /***/ 2016: /***/ function (module, exports, __webpack_require__) {
+    /***/ 8490: /***/ function (module, exports, __webpack_require__) {
       "use strict";
       /* __next_internal_client_entry_do_not_use__  cjs */
       Object.defineProperty(exports, "__esModule", {
@@ -40,15 +40,15 @@
         __webpack_require__(422)
       );
       const _head = /*#__PURE__*/ _interop_require_default._(
-        __webpack_require__(6074)
+        __webpack_require__(2457)
       );
-      const _getimgprops = __webpack_require__(9571);
-      const _imageconfig = __webpack_require__(6567);
-      const _imageconfigcontextsharedruntime = __webpack_require__(419);
-      const _warnonce = __webpack_require__(4486);
-      const _routercontextsharedruntime = __webpack_require__(162);
+      const _getimgprops = __webpack_require__(7932);
+      const _imageconfig = __webpack_require__(5706);
+      const _imageconfigcontextsharedruntime = __webpack_require__(9483);
+      const _warnonce = __webpack_require__(9035);
+      const _routercontextsharedruntime = __webpack_require__(4829);
       const _imageloader = /*#__PURE__*/ _interop_require_default._(
-        __webpack_require__(6996)
+        __webpack_require__(7240)
       );
       // This is replaced by webpack define plugin
       const configEnv = {
@@ -379,7 +379,7 @@
       /***/
     },
 
-    /***/ 9571: /***/ function (
+    /***/ 7932: /***/ function (
       __unused_webpack_module,
       exports,
       __webpack_require__
@@ -395,9 +395,9 @@
           return getImgProps;
         },
       });
-      const _warnonce = __webpack_require__(4486);
-      const _imageblursvg = __webpack_require__(133);
-      const _imageconfig = __webpack_require__(6567);
+      const _warnonce = __webpack_require__(9035);
+      const _imageblursvg = __webpack_require__(2642);
+      const _imageconfig = __webpack_require__(5706);
       const VALID_LOADING_VALUES =
         /* unused pure expression or super */ null && [
           "lazy",
@@ -561,6 +561,11 @@
             deviceSizes,
           };
         }
+        if (typeof defaultLoader === "undefined") {
+          throw new Error(
+            "images.loaderFile detected but the file is missing default export.\nRead more: https://nextjs.org/docs/messages/invalid-images-config"
+          );
+        }
         let loader = rest.loader || defaultLoader;
         // Remove property so it's not spread on <img> element
         delete rest.loader;
@@ -767,7 +772,7 @@
       /***/
     },
 
-    /***/ 133: /***/ function (__unused_webpack_module, exports) {
+    /***/ 2642: /***/ function (__unused_webpack_module, exports) {
       "use strict";
       /**
        * A shared function, used on both client and server, to generate a SVG blur placeholder.
@@ -822,7 +827,7 @@
       /***/
     },
 
-    /***/ 4085: /***/ function (
+    /***/ 503: /***/ function (
       __unused_webpack_module,
       exports,
       __webpack_require__
@@ -849,10 +854,10 @@
         },
       });
       const _interop_require_default = __webpack_require__(2430);
-      const _getimgprops = __webpack_require__(9571);
-      const _imagecomponent = __webpack_require__(2016);
+      const _getimgprops = __webpack_require__(7932);
+      const _imagecomponent = __webpack_require__(8490);
       const _imageloader = /*#__PURE__*/ _interop_require_default._(
-        __webpack_require__(6996)
+        __webpack_require__(7240)
       );
       function getImageProps(imgProps) {
         const { props } = (0, _getimgprops.getImgProps)(imgProps, {
@@ -884,7 +889,7 @@
       /***/
     },
 
-    /***/ 6996: /***/ function (__unused_webpack_module, exports) {
+    /***/ 7240: /***/ function (__unused_webpack_module, exports) {
       "use strict";
 
       Object.defineProperty(exports, "__esModule", {
@@ -919,7 +924,7 @@
       /***/
     },
 
-    /***/ 5237: /***/ function (
+    /***/ 396: /***/ function (
       __unused_webpack_module,
       __webpack_exports__,
       __webpack_require__
@@ -940,8 +945,8 @@
 
       // EXTERNAL MODULE: ./node_modules/.pnpm/react@18.2.0/node_modules/react/jsx-runtime.js
       var jsx_runtime = __webpack_require__(1527);
-      // EXTERNAL MODULE: ./node_modules/.pnpm/file+..+main-repo+packages+next+next-packed.tgz_react-dom@18.2.0_react@18.2.0/node_modules/next/image.js
-      var next_image = __webpack_require__(1577);
+      // EXTERNAL MODULE: ./node_modules/.pnpm/file+..+diff-repo+packages+next+next-packed.tgz_react-dom@18.2.0_react@18.2.0/node_modules/next/image.js
+      var next_image = __webpack_require__(73);
       var image_default = /*#__PURE__*/ __webpack_require__.n(next_image); // CONCATENATED MODULE: ./pages/nextjs.png
       /* harmony default export */ var nextjs = {
         src: "/_next/static/media/nextjs.cae0b805.png",
@@ -971,12 +976,12 @@
       /***/
     },
 
-    /***/ 1577: /***/ function (
+    /***/ 73: /***/ function (
       module,
       __unused_webpack_exports,
       __webpack_require__
     ) {
-      module.exports = __webpack_require__(4085);
+      module.exports = __webpack_require__(503);
 
       /***/
     },
@@ -987,7 +992,7 @@
       return __webpack_require__((__webpack_require__.s = moduleId));
     };
     /******/ __webpack_require__.O(0, [2888, 9774, 179], function () {
-      return __webpack_exec__(1552);
+      return __webpack_exec__(4070);
     });
     /******/ var __webpack_exports__ = __webpack_require__.O();
     /******/ _N_E = __webpack_exports__;
Diff for 8299-HASH.js
@@ -1,8 +1,8 @@
 "use strict";
 (self["webpackChunk_N_E"] = self["webpackChunk_N_E"] || []).push([
-  [8299],
+  [2764],
   {
-    /***/ 8299: /***/ function (module, exports, __webpack_require__) {
+    /***/ 2764: /***/ function (module, exports, __webpack_require__) {
       /* __next_internal_client_entry_do_not_use__  cjs */
       Object.defineProperty(exports, "__esModule", {
         value: true,
@@ -13,25 +13,25 @@
           return Image;
         },
       });
-      const _interop_require_default = __webpack_require__(4777);
-      const _interop_require_wildcard = __webpack_require__(353);
-      const _jsxruntime = __webpack_require__(6435);
+      const _interop_require_default = __webpack_require__(9380);
+      const _interop_require_wildcard = __webpack_require__(2077);
+      const _jsxruntime = __webpack_require__(2260);
       const _react = /*#__PURE__*/ _interop_require_wildcard._(
-        __webpack_require__(8288)
+        __webpack_require__(4978)
       );
       const _reactdom = /*#__PURE__*/ _interop_require_default._(
-        __webpack_require__(4364)
+        __webpack_require__(7)
       );
       const _head = /*#__PURE__*/ _interop_require_default._(
-        __webpack_require__(9369)
+        __webpack_require__(5175)
       );
-      const _getimgprops = __webpack_require__(2564);
-      const _imageconfig = __webpack_require__(578);
-      const _imageconfigcontextsharedruntime = __webpack_require__(8589);
-      const _warnonce = __webpack_require__(2528);
-      const _routercontextsharedruntime = __webpack_require__(2339);
+      const _getimgprops = __webpack_require__(7253);
+      const _imageconfig = __webpack_require__(6491);
+      const _imageconfigcontextsharedruntime = __webpack_require__(9382);
+      const _warnonce = __webpack_require__(3848);
+      const _routercontextsharedruntime = __webpack_require__(7897);
       const _imageloader = /*#__PURE__*/ _interop_require_default._(
-        __webpack_require__(1300)
+        __webpack_require__(3366)
       );
       // This is replaced by webpack define plugin
       const configEnv = {
@@ -363,7 +363,7 @@
       /***/
     },
 
-    /***/ 5416: /***/ function (
+    /***/ 7121: /***/ function (
       __unused_webpack_module,
       exports,
       __webpack_require__
@@ -377,9 +377,9 @@
           return AmpStateContext;
         },
       });
-      const _interop_require_default = __webpack_require__(4777);
+      const _interop_require_default = __webpack_require__(9380);
       const _react = /*#__PURE__*/ _interop_require_default._(
-        __webpack_require__(8288)
+        __webpack_require__(4978)
       );
       const AmpStateContext = _react.default.createContext({});
       if (false) {
@@ -388,7 +388,7 @@
       /***/
     },
 
-    /***/ 9392: /***/ function (__unused_webpack_module, exports) {
+    /***/ 7960: /***/ function (__unused_webpack_module, exports) {
       Object.defineProperty(exports, "__esModule", {
         value: true,
       });
@@ -410,7 +410,7 @@
       /***/
     },
 
-    /***/ 2564: /***/ function (
+    /***/ 7253: /***/ function (
       __unused_webpack_module,
       exports,
       __webpack_require__
@@ -424,9 +424,9 @@
           return getImgProps;
         },
       });
-      const _warnonce = __webpack_require__(2528);
-      const _imageblursvg = __webpack_require__(7910);
-      const _imageconfig = __webpack_require__(578);
+      const _warnonce = __webpack_require__(3848);
+      const _imageblursvg = __webpack_require__(558);
+      const _imageconfig = __webpack_require__(6491);
       const VALID_LOADING_VALUES =
         /* unused pure expression or super */ null && [
           "lazy",
@@ -590,6 +590,11 @@
             deviceSizes,
           };
         }
+        if (typeof defaultLoader === "undefined") {
+          throw new Error(
+            "images.loaderFile detected but the file is missing default export.\nRead more: https://nextjs.org/docs/messages/invalid-images-config"
+          );
+        }
         let loader = rest.loader || defaultLoader;
         // Remove property so it's not spread on <img> element
         delete rest.loader;
@@ -796,7 +801,7 @@
       /***/
     },
 
-    /***/ 9369: /***/ function (module, exports, __webpack_require__) {
+    /***/ 5175: /***/ function (module, exports, __webpack_require__) {
       /* __next_internal_client_entry_do_not_use__  cjs */
       Object.defineProperty(exports, "__esModule", {
         value: true,
@@ -817,19 +822,19 @@
           return defaultHead;
         },
       });
-      const _interop_require_default = __webpack_require__(4777);
-      const _interop_require_wildcard = __webpack_require__(353);
-      const _jsxruntime = __webpack_require__(6435);
+      const _interop_require_default = __webpack_require__(9380);
+      const _interop_require_wildcard = __webpack_require__(2077);
+      const _jsxruntime = __webpack_require__(2260);
       const _react = /*#__PURE__*/ _interop_require_wildcard._(
-        __webpack_require__(8288)
+        __webpack_require__(4978)
       );
       const _sideeffect = /*#__PURE__*/ _interop_require_default._(
-        __webpack_require__(1620)
+        __webpack_require__(5894)
       );
-      const _ampcontextsharedruntime = __webpack_require__(5416);
-      const _headmanagercontextsharedruntime = __webpack_require__(7662);
-      const _ampmode = __webpack_require__(9392);
-      const _warnonce = __webpack_require__(2528);
+      const _ampcontextsharedruntime = __webpack_require__(7121);
+      const _headmanagercontextsharedruntime = __webpack_require__(5237);
+      const _ampmode = __webpack_require__(7960);
+      const _warnonce = __webpack_require__(3848);
       function defaultHead(inAmpMode) {
         if (inAmpMode === void 0) inAmpMode = false;
         const head = [
@@ -1005,7 +1010,7 @@
       /***/
     },
 
-    /***/ 7910: /***/ function (__unused_webpack_module, exports) {
+    /***/ 558: /***/ function (__unused_webpack_module, exports) {
       /**
        * A shared function, used on both client and server, to generate a SVG blur placeholder.
        */
@@ -1059,7 +1064,7 @@
       /***/
     },
 
-    /***/ 8589: /***/ function (
+    /***/ 9382: /***/ function (
       __unused_webpack_module,
       exports,
       __webpack_require__
@@ -1073,11 +1078,11 @@
           return ImageConfigContext;
         },
       });
-      const _interop_require_default = __webpack_require__(4777);
+      const _interop_require_default = __webpack_require__(9380);
       const _react = /*#__PURE__*/ _interop_require_default._(
-        __webpack_require__(8288)
+        __webpack_require__(4978)
       );
-      const _imageconfig = __webpack_require__(578);
+      const _imageconfig = __webpack_require__(6491);
       const ImageConfigContext = _react.default.createContext(
         _imageconfig.imageConfigDefault
       );
@@ -1087,7 +1092,7 @@
       /***/
     },
 
-    /***/ 578: /***/ function (__unused_webpack_module, exports) {
+    /***/ 6491: /***/ function (__unused_webpack_module, exports) {
       Object.defineProperty(exports, "__esModule", {
         value: true,
       });
@@ -1134,7 +1139,7 @@
       /***/
     },
 
-    /***/ 1300: /***/ function (__unused_webpack_module, exports) {
+    /***/ 3366: /***/ function (__unused_webpack_module, exports) {
       Object.defineProperty(exports, "__esModule", {
         value: true,
       });
@@ -1167,7 +1172,7 @@
       /***/
     },
 
-    /***/ 2339: /***/ function (
+    /***/ 7897: /***/ function (
       __unused_webpack_module,
       exports,
       __webpack_require__
@@ -1181,9 +1186,9 @@
           return RouterContext;
         },
       });
-      const _interop_require_default = __webpack_require__(4777);
+      const _interop_require_default = __webpack_require__(9380);
       const _react = /*#__PURE__*/ _interop_require_default._(
-        __webpack_require__(8288)
+        __webpack_require__(4978)
       );
       const RouterContext = _react.default.createContext(null);
       if (false) {
@@ -1192,7 +1197,7 @@
       /***/
     },
 
-    /***/ 1620: /***/ function (
+    /***/ 5894: /***/ function (
       __unused_webpack_module,
       exports,
       __webpack_require__
@@ -1206,7 +1211,7 @@
           return SideEffect;
         },
       });
-      const _react = __webpack_require__(8288);
+      const _react = __webpack_require__(4978);
       const isServer = typeof window === "undefined";
       const useClientOnlyLayoutEffect = isServer
         ? () => {}
Commit: cda86fc

@ojj1123 ojj1123 marked this pull request as draft April 4, 2024 18:46
@ojj1123 ojj1123 marked this pull request as ready for review April 5, 2024 07:23
@ojj1123
Copy link
Contributor Author

ojj1123 commented Apr 5, 2024

I added the test. Please review this PR!

@ojj1123 ojj1123 requested a review from styfle April 5, 2024 07:25
@ojj1123
Copy link
Contributor Author

ojj1123 commented Apr 9, 2024

@styfle
Sorry for mentioning you but I was wondering if you could review this PR?

@ijjk
Copy link
Member

ijjk commented Apr 9, 2024

Allow CI Workflow Run

  • approve CI run for commit: 2a2dcaf

Note: this should only be enabled once the PR is ready to go and can only be enabled by a maintainer

@ojj1123
Copy link
Contributor Author

ojj1123 commented Apr 10, 2024

82eeab4

@styfle
I fixed the test suite.

@styfle styfle changed the title feat: show the concrete error message if the loader file don't export a default function fix: show the error message if images.loaderFile doesn't export a default function Apr 10, 2024
Copy link
Member

@styfle styfle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work, thanks! 🎉

@styfle styfle enabled auto-merge (squash) April 10, 2024 18:03
@styfle styfle merged commit 04c87ae into vercel:canary Apr 10, 2024
73 checks passed
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 26, 2024
@ojj1123 ojj1123 deleted the fix/custom-loader-config branch April 28, 2024 01:27
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

TypeError: Cannot use 'in' operator to search for '__next_img_default' in undefined
3 participants