question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Webpack config.externals is undefined in Next 8.1.0?

See original GitHub issue

Question 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:closed
  • Created 4 years ago
  • Comments:9 (6 by maintainers)

github_iconTop GitHub Comments

4reactions
timneutkenscommented, Apr 22, 2019

Note that you should actually make the value undefined if you’re not adding anything to it.

3reactions
aekscocommented, Apr 22, 2019

@timneutkens Thanks for the reply and the context! I’ve added the following line to my next.config.js file which solves the problem:

config.externals = config.externals || [];

Glad to know this is actually a solution to the problem and not just a kludgey band-aid. Thanks again!

Read more comments on GitHub >

github_iconTop Results From Across the Web

undefined-webpack-config - Next.js
The value returned from the custom webpack function in your next.config.js was undefined. This can occur from the initial config value not being...
Read more >
Webpack Fabric external is resolving to undefined
An error occurs when trying to set up the fabric js library as an external within a (typescript + webpack ) project. Fabric...
Read more >
uncaught referenceerror: $ is not defined webpack - You.com
Since you use nodeExternals in web app you get CommonJS modules, that expects built in node require function. So just remove it to...
Read more >
Externals - webpack
config.js indicates that the module jquery in import $ from 'jquery' should be excluded from bundling. In order to replace this module ...
Read more >
Changelog - Cypress Documentation
To leverage external dependencies in cy.origin() callbacks, set the new e2e.experimentalOriginDependencies configuration option to true . Addresses #21471.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found