Webpack 5 Adoption · vercel/next.js · Discussion #23498 (original) (raw)
Hi. I updated my project to Next.js 12 and activated the Webpack to version 5. And now next dev
and next build
doesn't work. Show the following error:
Build error occurred ValidationError: Invalid configuration object. Webpack has been initialized using a configuration object that does not match the API schema.
- configuration.module.rules[5] should be one of these:
["..." | object { assert?, compiler?, dependency?, descriptionData?, enforce?, exclude?, generator?, include?, issuer?, issuerLayer?, layer?, loader?, mimetype?, oneOf?, options?, parser?, realResource?, resolve?, resource?, resourceFragment?, resourceQuery?, rules?, scheme?, sideEffects?, test?, type?, use? }, ...]
-> A rule.
Details:
- configuration.module.rules[5].loader should be a non-empty string. -> A loader request. at validate (/Users/brunodulcetti/repositories/mosaico/cupom/site/node_modules/next/dist/compiled/schema-utils3/index.js:1:153662) at validateSchema (/Users/brunodulcetti/repositories/mosaico/cupom/site/node_modules/next/dist/compiled/webpack/bundle5.js:130764:2) at create (/Users/brunodulcetti/repositories/mosaico/cupom/site/node_modules/next/dist/compiled/webpack/bundle5.js:134244:24) at webpack (/Users/brunodulcetti/repositories/mosaico/cupom/site/node_modules/next/dist/compiled/webpack/bundle5.js:134291:32) at Object.f [as webpack] (/Users/brunodulcetti/repositories/mosaico/cupom/site/node_modules/next/dist/compiled/webpack/bundle5.js:89548:16) at /Users/brunodulcetti/repositories/mosaico/cupom/site/node_modules/next/dist/build/compiler.js:31:40 at new Promise () at Object.runCompiler (/Users/brunodulcetti/repositories/mosaico/cupom/site/node_modules/next/dist/build/compiler.js:30:12) at /Users/brunodulcetti/repositories/mosaico/cupom/site/node_modules/next/dist/build/index.js:374:59 at Span.traceAsyncFn (/Users/brunodulcetti/repositories/mosaico/cupom/site/node_modules/next/dist/trace/trace.js:74:26) { errors: [ { keyword: 'oneOf', dataPath: '.module.rules', schemaPath: '#/properties/rules/oneOf', params: [Object], message: 'should match exactly one schema in oneOf', schema: [Array], parentSchema: [Object], data: [Array], children: [Array] } ], schema: { definitions: { Amd: [Object], AssetFilterItemTypes: [Object], AssetFilterTypes: [Object], AssetGeneratorDataUrl: [Object], AssetGeneratorDataUrlFunction: [Object], AssetGeneratorDataUrlOptions: [Object], AssetGeneratorOptions: [Object], AssetInlineGeneratorOptions: [Object], AssetModuleFilename: [Object], AssetParserDataUrlFunction: [Object], AssetParserDataUrlOptions: [Object], AssetParserOptions: [Object], AssetResourceGeneratorOptions: [Object], AuxiliaryComment: [Object], Bail: [Object], CacheOptions: [Object], CacheOptionsNormalized: [Object], Charset: [Object], ChunkFilename: [Object], ChunkFormat: [Object], ChunkLoadTimeout: [Object], ChunkLoading: [Object], ChunkLoadingGlobal: [Object], ChunkLoadingType: [Object], Clean: [Object], CleanOptions: [Object], CompareBeforeEmit: [Object], Context: [Object], CrossOriginLoading: [Object], Dependencies: [Object], DevServer: [Object], DevTool: [Object], DevtoolFallbackModuleFilenameTemplate: [Object], DevtoolModuleFilenameTemplate: [Object], DevtoolNamespace: [Object], EmptyGeneratorOptions: [Object], EmptyParserOptions: [Object], EnabledChunkLoadingTypes: [Object], EnabledLibraryTypes: [Object], EnabledWasmLoadingTypes: [Object], Entry: [Object], EntryDescription: [Object], EntryDescriptionNormalized: [Object], EntryDynamic: [Object], EntryDynamicNormalized: [Object], EntryFilename: [Object], EntryItem: [Object], EntryNormalized: [Object], EntryObject: [Object], EntryRuntime: [Object], EntryStatic: [Object], EntryStaticNormalized: [Object], EntryUnnamed: [Object], Environment: [Object], Experiments: [Object], ExperimentsCommon: [Object], ExperimentsNormalized: [Object], ExternalItem: [Object], ExternalItemFunctionData: [Object], ExternalItemValue: [Object], Externals: [Object], ExternalsPresets: [Object], ExternalsType: [Object], FileCacheOptions: [Object], Filename: [Object], FilenameTemplate: [Object], FilterItemTypes: [Object], FilterTypes: [Object], GeneratorOptionsByModuleType: [Object], GlobalObject: [Object], HashDigest: [Object], HashDigestLength: [Object], HashFunction: [Object], HashSalt: [Object], HotUpdateChunkFilename: [Object], HotUpdateGlobal: [Object], HotUpdateMainFilename: [Object], HttpUriAllowedUris: [Object], HttpUriOptions: [Object], HttpUriOptionsAllowedUris: [Object], IgnoreWarnings: [Object], IgnoreWarningsNormalized: [Object], Iife: [Object], ImportFunctionName: [Object], ImportMetaName: [Object], InfrastructureLogging: [Object], JavascriptParserOptions: [Object], Layer: [Object], LazyCompilationDefaultBackendOptions: [Object], LazyCompilationOptions: [Object], Library: [Object], LibraryCustomUmdCommentObject: [Object], LibraryCustomUmdObject: [Object], LibraryExport: [Object], LibraryName: [Object], LibraryOptions: [Object], LibraryType: [Object], Loader: [Object], MemoryCacheOptions: [Object], Mode: [Object], ModuleFilterItemTypes: [Object], ModuleFilterTypes: [Object], ModuleOptions: [Object], ModuleOptionsNormalized: [Object], Name: [Object], NoParse: [Object], Node: [Object], NodeOptions: [Object], Optimization: [Object], OptimizationRuntimeChunk: [Object], OptimizationRuntimeChunkNormalized: [Object], OptimizationSplitChunksCacheGroup: [Object], OptimizationSplitChunksGetCacheGroups: [Object], OptimizationSplitChunksOptions: [Object], OptimizationSplitChunksSizes: [Object], Output: [Object], OutputModule: [Object], OutputNormalized: [Object], Parallelism: [Object], ParserOptionsByModuleType: [Object], Path: [Object], Pathinfo: [Object], Performance: [Object], PerformanceOptions: [Object], Plugins: [Object], Profile: [Object], PublicPath: [Object], RawPublicPath: [Object], RecordsInputPath: [Object], RecordsOutputPath: [Object], RecordsPath: [Object], Resolve: [Object], ResolveAlias: [Object], ResolveLoader: [Object], ResolveOptions: [Object], ResolvePluginInstance: [Object], RuleSetCondition: [Object], RuleSetConditionAbsolute: [Object], RuleSetConditionOrConditions: [Object], RuleSetConditionOrConditionsAbsolute: [Object], RuleSetConditions: [Object], RuleSetConditionsAbsolute: [Object], RuleSetLoader: [Object], RuleSetLoaderOptions: [Object], RuleSetLogicalConditions: [Object], RuleSetLogicalConditionsAbsolute: [Object], RuleSetRule: [Object], RuleSetRules: [Object], RuleSetUse: [Object], RuleSetUseItem: [Object], ScriptType: [Object], SnapshotOptions: [Object], SourceMapFilename: [Object], SourcePrefix: [Object], StatsOptions: [Object], StatsValue: [Object], StrictModuleErrorHandling: [Object], StrictModuleExceptionHandling: [Object], Target: [Object], TrustedTypes: [Object], UmdNamedDefine: [Object], UniqueName: [Object], WarningFilterItemTypes: [Object], WarningFilterTypes: [Object], WasmLoading: [Object], WasmLoadingType: [Object], Watch: [Object], WatchOptions: [Object], WebassemblyModuleFilename: [Object], WebpackOptionsNormalized: [Object], WebpackPluginFunction: [Object], WebpackPluginInstance: [Object] }, title: 'WebpackOptions', description: 'Options object as provided by the user.', type: 'object', additionalProperties: false, properties: { amd: [Object], bail: [Object], cache: [Object], context: [Object], dependencies: [Object], devServer: [Object], devtool: [Object], entry: [Object], experiments: [Object], externals: [Object], externalsPresets: [Object], externalsType: [Object], ignoreWarnings: [Object], infrastructureLogging: [Object], loader: [Object], mode: [Object], module: [Object], name: [Object], node: [Object], optimization: [Object], output: [Object], parallelism: [Object], performance: [Object], plugins: [Object], profile: [Object], recordsInputPath: [Object], recordsOutputPath: [Object], recordsPath: [Object], resolve: [Object], resolveLoader: [Object], snapshot: [Object], stats: [Object], target: [Object], watch: [Object], watchOptions: [Object] } }, headerName: 'Webpack', baseDataPath: 'configuration', postFormatter: [Function: postFormatter] } error Command failed with exit code 1.
The fifth index of rules follows below:
{ test: /.+(js|jsx|mjs|ts|tsx)$/, loader: { loader: 'next-swc-loader', options: { isServer: true, pagesDir: '/Users/brunodulcetti/repositories/mosaico/cupom/site/src/pages', hasReactRefresh: false, fileReading: true, nextConfig: [Object], jsConfig: [Object] } }, include: [Function (anonymous)] }
next.config.js
const path = require('path');
const nextEnv = require('next-env'); const withPlugins = require('next-compose-plugins'); const withTM = require('next-transpile-modules')([ '@asteroid/analytics', '@asteroid/components', '@asteroid/icons', '@asteroid/shared', ]);
const withNextEnv = nextEnv({ staticPrefix: 'BRAND', });
const {BRAND} = process.env;
const securityHeaders = [ { key: 'X-Frame-Options', value: 'SAMEORIGIN', }, ];
const nextConfig = {
images: {
domains: ['s.zst.com.br'],
},
webpack: config => {
config.resolve.alias = {
...config.resolve.alias,
'@asteroid/theme': path.resolve(
__dirname,
node_modules/@asteroid/components/src/theme/${BRAND}/
,
),
'@theme': path.resolve(__dirname, 'src/theme/'),
};
config.module.rules.push({
test: /\.svg$/i,
issuer: /\.(js|ts|md)x?$/,
use: [
{
loader: '@svgr/webpack',
options: {
prettier: false,
svgo: true,
svgoConfig: {plugins: [{removeViewBox: false}]},
titleProp: true,
},
},
],
});
return config;
}, basePath: '/cupom-de-desconto', eslint: { ignoreDuringBuilds: true, }, staticPageGenerationTimeout: 120, compress: true,
async headers() { return [ { source: '/:all*(svg|jpg|png)', locale: false, headers: [ { key: 'Cache-Control', value: 'public, max-age=300, must-revalidate', }, ], }, { source: '/:path*', headers: securityHeaders, }, ]; }, };
module.exports = withPlugins([[[withNextEnv]], [withTM]], nextConfig);
package.json
{ "name": "cupom-front", "version": "0.0.20", "scripts": { "dev": "NODE_OPTIONS='--inspect' next dev", "dev:zoom": "NEXT_PUBLIC_BRAND=zoom BRAND=zoom yarn dev", "prod:zoom": "NEXT_PUBLIC_BRAND=zoom BRAND=zoom next build", "dev:buscape": "NEXT_PUBLIC_BRAND=buscape BRAND=buscape yarn dev", "prod:buscape": "NEXT_PUBLIC_BRAND=buscape BRAND=buscape next build", "build": "next build", "start": "next start", "postbuild": "next-sitemap" }, "dependencies": { "@asteroid/analytics": "^3.51.0", "@asteroid/components": "^3.51.0", "@asteroid/icons": "^3.51.0", "@asteroid/shared": "3.51.0", "@chakra-ui/icons": "^1.0.13", "@chakra-ui/react": "^1.4.2", "@chakra-ui/theme-tools": "1.1.2", "@emotion/react": "11.1.5", "@emotion/styled": "11.1.5", "@fontsource/montserrat": "^4.3.0", "bootstrap": "4.4.1", "classnames": "^2.3.1", "cross-fetch": "^3.1.4", "currency.js": "^1.2.2", "framer-motion": "^4.0.3", "js-cookie": "^3.0.1", "jwt-simple": "^0.5.6", "lodash": "^4.17.21", "moment": "^2.29.1", "newrelic": "^7.5.2", "next": "12.0.7", "next-compose-plugins": "^2.2.1", "next-env": "^1.1.1", "next-seo": "^4.24.0", "next-transpile-modules": "^6.4.0", "node-cache": "^5.1.2", "node-sass": "4.14.1", "nookies": "^2.5.2", "react": "^17.0.2", "react-bootstrap": "^1.6.3", "react-clamp-lines": "^3.0.2", "react-dom": "^17.0.2", "react-instantsearch-core": "^6.12.1", "react-lite-youtube-embed": "^2.2.2", "react-modal": "^3.14.3", "react-multi-carousel": "^2.8.2", "react-rating": "^2.0.5", "react-responsive-carousel": "^3.2.21", "react-share": "^4.4.0", "react-swipeable": "^7.0.0", "react-tabs": "^3.2.2", "snarkdown": "^2.0.0", "styled-components": "^5.3.5" }, "devDependencies": { "@asteroid/eslint-config": "^3.51.0", "@asteroid/prettier-config": "^3.51.0", "@asteroid/stylelint-config": "^3.51.0", "@svgr/webpack": "^5.5.0", "@testing-library/jest-dom": "^5.16.5", "@testing-library/react": "^13.3.0", "@testing-library/react-hooks": "^8.0.1", "@testing-library/user-event": "^14.4.3", "@types/node": "^14.6.0", "@types/react": "^17.0.3", "@types/react-dom": "^17.0.3", "@types/styled-components": "^5.1.26", "@typescript-eslint/eslint-plugin": "^4.28.2", "@typescript-eslint/parser": "^4.28.2", "babel-eslint": "^10.1.0", "eslint": "^7.30.0", "eslint-config-airbnb": "^18.2.1", "eslint-config-next": "^11.0.1", "eslint-config-prettier": "^8.3.0", "eslint-plugin-import": "^2.23.4", "eslint-plugin-jsx-a11y": "^6.4.1", "eslint-plugin-prettier": "^3.4.0", "eslint-plugin-react": "^7.24.0", "eslint-plugin-react-hooks": "^4.2.0", "file-loader": "^6.2.0", "next-sitemap": "^1.6.124", "prettier": "^2.3.2", "typescript": "4.3.2" }, "license": "MIT", "resolutions": { "@types/react": "^17.0.3", "@types/react-dom": "^17.0.3", "styled-components": "^5" } }