SolidZORO / next-plugin-antd-less

🎩 Use Antd (Less) with Next.js v12, Zero Dependency on other Next-Plugins.
MIT License
345 stars 48 forks source link

Failed to use webpack 5 configuration on Next 11 #62

Closed nelsliu9121 closed 3 years ago

nelsliu9121 commented 3 years ago

Next.js 11 announced recently and it is making webpack 5 the default bundler. The future.webpack5 config in next.config.js has been moved to webpack5 and it is set to true by default. (see this)

To reproduce, go to this CodeSandbox

This is the error printed when running npm run dev:

(node:5223) [DEP_WEBPACK_EXTERNALS_FUNCTION_PARAMETERS] DeprecationWarning: The externals-function should be defined like ({context, request}, cb) => { ... }
(node:5223) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'startsWith' of undefined
    at handleExternals (/Users/nelsliu9121/Codes/next-plugin-antd-less-next11-reproduction/node_modules/next/dist/build/webpack-config.js:48:23)
    at Array.webpackConfig.externals._webpack.isWebpack5.require.resolve.paths (/Users/nelsliu9121/Codes/next-plugin-antd-less-next11-reproduction/node_modules/next/dist/build/webpack-config.js:87:77)
    at webpackConfig.externals (/Users/nelsliu9121/Codes/next-plugin-antd-less-next11-reproduction/node_modules/next-plugin-antd-less/overrideWebpackConfig.js:337:62)
    at /Users/nelsliu9121/Codes/next-plugin-antd-less-next11-reproduction/node_modules/next/dist/compiled/webpack/bundle5.js:53948:21
    at deprecated (internal/util.js:89:15)
    at handleExternals (/Users/nelsliu9121/Codes/next-plugin-antd-less-next11-reproduction/node_modules/next/dist/compiled/webpack/bundle5.js:54095:8)
    at next (/Users/nelsliu9121/Codes/next-plugin-antd-less-next11-reproduction/node_modules/next/dist/compiled/webpack/bundle5.js:54073:9)
    at handleExternals (/Users/nelsliu9121/Codes/next-plugin-antd-less-next11-reproduction/node_modules/next/dist/compiled/webpack/bundle5.js:54078:7)
    at /Users/nelsliu9121/Codes/next-plugin-antd-less-next11-reproduction/node_modules/next/dist/compiled/webpack/bundle5.js:54175:5
    at Hook.eval [as callAsync] (eval at create (/Users/nelsliu9121/Codes/next-plugin-antd-less-next11-reproduction/node_modules/next/dist/compiled/webpack/bundle5.js:31934:10), <anonymous>:35:1)
morellodev commented 3 years ago

I analyzed the issue, the lib does the test nextConfig.config.future && nextConfig.config.future.webpack5 to enable the Webpack 5 config. In Next.js 11+, the flag to explicitly disable Webpack 5 has been moved as a top level property on the Next.js configuration, and if not specified WP5 is enabled by default.