Next.js Discord

Discord Forum

Setting CDN URL for assets with webpack

Western Gull posted this in #help-forum
Open in Discord
Western GullOP
I’m updating an old Next.js app to Next 13, which entails updating the built-in Webpack config. My config includes a rule to rewrite the URLs of static assets so that they can be served from a CDN (the deployed app runs on Netlify, but I’d prefer to keep static assets on my own CDN). The rule in question looks like this:

  test: /\.(ico|icns|png|jpg|jpeg|svg|gif|ttf|woff|mp3)$/,
  type: 'asset/resource',
  generator: {
    emit: !isServer,
    filename: `static/[name].[hash:8][ext]`,
    publicPath: (url) => `${cdnHost}/_next/static/${url}`,

The issue is that the generated URL once deployed looks like:[object Object]static/favicon.e72aff1c.ico

Can anyone explain why I’m getting this [object Object] in the middle of my URL?

0 Replies