Next.js Discord

Discord Forum

catch 22 in next.js 14.2.1

Answered
Asian black bear posted this in #help-forum
Open in Discord
Asian black bearOP
between:
hostname xyz not configured under images in your 'next.config.js',
and if i change 'next.config.cjs' to 'js', it solves this error, but in the console i see:

ReferenceError: module is not defined in ES module scope
This file is being treated as an ES module because it has a '.js' file extension and '/home/wixur/Projects/thrifty/package.json' contains "type": "module". To treat it as a CommonJS script, rename it to use the '.cjs' file extension.


so if i change cjs to js, it solves the error, but in the console i see...

how to solve this?

next.config.cjs/js:

/** @type {import('next').NextConfig} */
const nextConfig = {
  // allows to pass serverasync functions to client components with the "use server" directive inside them
  images: {
    remotePatterns:
      [{
        protocol: 'https',
        hostname: 'images.unsplash.com',
      }, {
        protocol: 'https',
        hostname: 'plus.unsplash.com',
      }, {
        protocol: 'https',
        hostname: 'f.nooncdn.com',
        pathname: '/en/women/**'
      }, {
        protocol: 'https',
        hostname: 'picsum.photos',
      }],
  },
};

module.exports = nextConfig;


previously it worked without specifying a pathname, now not even with one.
Answered by Asian black bear
after changing the last line, it didn't work with the cjs extension, i changed it to js, it didn't work either, but i removed the pathname and it worked!!!

thanks a lot for your help, you saved me!!!
View full answer

8 Replies

Asian black bearOP
i downgraded to next.js 14.1.0 and i have the same problem.
@joulev do you have `type: module` in your package.json?
Asian black bearOP
yes
try this
/** @type {import('next').NextConfig} */
const nextConfig = {
  // allows to pass serverasync functions to client components with the "use server" directive inside them
  images: {
    remotePatterns:
      [{
        protocol: 'https',
        hostname: 'images.unsplash.com',
      }, {
        protocol: 'https',
        hostname: 'plus.unsplash.com',
      }, {
        protocol: 'https',
        hostname: 'f.nooncdn.com',
        pathname: '/en/women/**'
      }, {
        protocol: 'https',
        hostname: 'picsum.photos',
      }],
  },
};

- module.exports = nextConfig;
+ export default nextConfig;
change the last line
Answer
well this time you saved yourself haha, good luck have fun coding
@joulev well this time you saved yourself haha, good luck have fun coding
Asian black bearOP
thank you!!!