Webpack config.externals is undefined in Next 8.1.0?
See original GitHub issueQuestion about Next.js
I’m not sure if this qualifies as a “bug” per se, as we’re engaging with some wild chicanery in our next.config.js, but there was a change in next@8.1.0 that broke our current configuration.
next.config.js (simplified)
module.exports = withTypescript({
webpack: (config, options) => {
const updatedConfig = withSass({
// SASS options here
}).webpack(config, options);
updatedConfig.resolve.symlinks = false;
updatedConfig.externals = config.externals.map(external => {
// Some custom dependency resolution here
});
// Returns the customized Next.js configuration
return updatedConfig;
}
});
This causes no problems on next@8.0.4 - however, after updating to 8.1.0 I started seeing the following error:
(node:45880) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'map' of undefined
at Object.webpack (/Users/aeksco/project/web/next.config.js:43:52)
at Object.webpack (/Users/aeksco/project/web/node_modules/@zeit/next-typescript/index.js:57:27)
at Object.getBaseWebpackConfig [as default] (/Users/aeksco/project/web/node_modules/next/dist/build/webpack-config.js:308:32)
at HotReloader.getWebpackConfig (/Users/aeksco/project/web/node_modules/next/dist/server/hot-reloader.js:162:37)
It appears that the Webpack configuration object passed into the webpack function does not include an externals array, which causes our customized configuration to explode when we try to run config.externals.map(...)
I was curious if the missing config.externals array is a bug, or if we’re doing something that’s so completely non-standard that the problem is really with our approach.
Any help or insight is appreciated - thanks!
Issue Analytics
- State:
- Created 4 years ago
- Comments:9 (6 by maintainers)

Top Related StackOverflow Question
Note that you should actually make the value undefined if you’re not adding anything to it.
@timneutkens Thanks for the reply and the context! I’ve added the following line to my
next.config.jsfile which solves the problem:Glad to know this is actually a solution to the problem and not just a kludgey band-aid. Thanks again!