Module not found: Error: Can't resolve 'encoding' when deploying Next.js Commerce template

I’m getting this error when trying to deploy Next Commerce https://github.com/vercel/commerce

I did,

The XDN deploy step flagged an error with my next.config.js needing withXDN and withServiceWorker:

🛠️  Building your app for deployment on the MOOVWEB XDN
Error: Next.js is not properly configured for deployment on the Moovweb XDN. Please add the withXDN() plugin to next.config.js.
      
For example:
  
  const { withXDN, withServiceWorker } = require('@xdn/next/config')

  module.exports = withXDN(withServiceWorker({
    // additional Next.js config options here
  }))

Please update next.config.js file and try again. If that file does not exist, simply add the example above to the root directory of your app.

However, after correcting my next.config.js and running xdn deploy again I get a new error:

🛠️  Building your app for deployment on the MOOVWEB XDN
(node:87789) [DEP_WEBPACK_SINGLE_ENTRY_PLUGIN] DeprecationWarning: SingleEntryPlugin was renamed to EntryPlugin
info  - Creating an optimized production build...
(node:87805) [DEP_WEBPACK_SINGLE_ENTRY_PLUGIN] DeprecationWarning: SingleEntryPlugin was renamed to EntryPlugin
> Creating service worker...
(node:87805) [DEP_WEBPACK_COMPILATION_ASSETS] DeprecationWarning: Compilation.assets will be frozen in future, all modifications are deprecated.
BREAKING CHANGE: No more changes should happen to Compilation.assets after sealing the Compilation.
	Do changes to assets earlier, e. g. in Compilation.hooks.processAssets.
	Make sure to select an appropriate stage from Compilation.PROCESS_ASSETS_STAGE_*.
<w> [webpack.cache.PackFileCacheStrategy] Serializing big strings (127kiB) impacts deserialization performance (consider using Buffer instead and decode when needed)
<w> [webpack.cache.PackFileCacheStrategy] Serializing big strings (131kiB) impacts deserialization performance (consider using Buffer instead and decode when needed)
> Optimizing serverless functions (Webpack 5)
Failed to compile.

ModuleNotFoundError: Module not found: Error: Can't resolve 'encoding' in '/Users/ishananand/code2/experiments/commerce/node_modules/node-fetch/lib'


> Build error occurred
Error: > Build failed because of webpack errors
    at build (/Users/ishananand/code2/experiments/commerce/node_modules/next/dist/build/index.js:15:918)

You can resolve this problem by

  • Run yarn add encoding in your project directory
  • Clear the next directory in your project by running rm -rf .next in the project directory
  • Re-running xdn deploy

Note that you’ll also need to put your BigCommerce API keys in .env.local as well for the deploy to successfully complete.