config.js 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = loadConfig;
  6. Object.defineProperty(exports, "DomainLocale", {
  7. enumerable: true,
  8. get: function() {
  9. return _configShared.DomainLocale;
  10. }
  11. });
  12. Object.defineProperty(exports, "NextConfig", {
  13. enumerable: true,
  14. get: function() {
  15. return _configShared.NextConfig;
  16. }
  17. });
  18. Object.defineProperty(exports, "normalizeConfig", {
  19. enumerable: true,
  20. get: function() {
  21. return _configShared.normalizeConfig;
  22. }
  23. });
  24. exports.setHttpAgentOptions = setHttpAgentOptions;
  25. var _path = require("path");
  26. var _url = require("url");
  27. var _http = require("http");
  28. var _https = require("https");
  29. var _findUp = _interopRequireDefault(require("next/dist/compiled/find-up"));
  30. var _chalk = _interopRequireDefault(require("../lib/chalk"));
  31. var Log = _interopRequireWildcard(require("../build/output/log"));
  32. var _constants = require("../shared/lib/constants");
  33. var _utils = require("../shared/lib/utils");
  34. var _configShared = require("./config-shared");
  35. var _configUtils = require("./config-utils");
  36. var _imageConfig = require("../shared/lib/image-config");
  37. var _env = require("@next/env");
  38. var _ciInfo = require("../telemetry/ci-info");
  39. async function loadConfig(phase, dir, customConfig) {
  40. await (0, _env).loadEnvConfig(dir, phase === _constants.PHASE_DEVELOPMENT_SERVER, Log);
  41. (0, _configUtils).loadWebpackHook();
  42. let configFileName = "next.config.js";
  43. if (customConfig) {
  44. return assignDefaults({
  45. configOrigin: "server",
  46. configFileName,
  47. ...customConfig
  48. });
  49. }
  50. const path = await (0, _findUp).default(_constants.CONFIG_FILES, {
  51. cwd: dir
  52. });
  53. // If config file was found
  54. if (path == null ? void 0 : path.length) {
  55. var ref;
  56. configFileName = (0, _path).basename(path);
  57. let userConfigModule;
  58. try {
  59. // `import()` expects url-encoded strings, so the path must be properly
  60. // escaped and (especially on Windows) absolute paths must pe prefixed
  61. // with the `file://` protocol
  62. if (process.env.__NEXT_TEST_MODE === "jest") {
  63. // dynamic import does not currently work inside of vm which
  64. // jest relies on so we fall back to require for this case
  65. // https://github.com/nodejs/node/issues/35889
  66. userConfigModule = require(path);
  67. } else {
  68. userConfigModule = await import((0, _url).pathToFileURL(path).href);
  69. }
  70. } catch (err) {
  71. Log.error(`Failed to load ${configFileName}, see more info here https://nextjs.org/docs/messages/next-config-error`);
  72. throw err;
  73. }
  74. const userConfig = await (0, _configShared).normalizeConfig(phase, userConfigModule.default || userConfigModule);
  75. const validateResult = (0, _configShared).validateConfig(userConfig);
  76. if (validateResult.errors) {
  77. Log.warn(`Invalid next.config.js options detected: `);
  78. // Only load @segment/ajv-human-errors when invalid config is detected
  79. const { AggregateAjvError } = require("next/dist/compiled/@segment/ajv-human-errors");
  80. const aggregatedAjvErrors = new AggregateAjvError(validateResult.errors, {
  81. fieldLabels: "js"
  82. });
  83. for (const error of aggregatedAjvErrors){
  84. console.error(` - ${error.message}`);
  85. }
  86. console.error("\nSee more info here: https://nextjs.org/docs/messages/invalid-next-config");
  87. }
  88. if (Object.keys(userConfig).length === 0) {
  89. Log.warn(`Detected ${configFileName}, no exported configuration found. https://nextjs.org/docs/messages/empty-configuration`);
  90. }
  91. if (userConfig.target && !targets.includes(userConfig.target)) {
  92. throw new Error(`Specified target is invalid. Provided: "${userConfig.target}" should be one of ${targets.join(", ")}`);
  93. }
  94. if (userConfig.target && userConfig.target !== "server") {
  95. Log.warn("The `target` config is deprecated and will be removed in a future version.\n" + "See more info here https://nextjs.org/docs/messages/deprecated-target-config");
  96. }
  97. if ((ref = userConfig.amp) == null ? void 0 : ref.canonicalBase) {
  98. const { canonicalBase } = userConfig.amp || {};
  99. userConfig.amp = userConfig.amp || {};
  100. userConfig.amp.canonicalBase = (canonicalBase.endsWith("/") ? canonicalBase.slice(0, -1) : canonicalBase) || "";
  101. }
  102. if (process.env.NEXT_PRIVATE_TARGET || _ciInfo.hasNextSupport) {
  103. userConfig.target = process.env.NEXT_PRIVATE_TARGET || "server";
  104. }
  105. return assignDefaults({
  106. configOrigin: (0, _path).relative(dir, path),
  107. configFile: path,
  108. configFileName,
  109. ...userConfig
  110. });
  111. } else {
  112. const configBaseName = (0, _path).basename(_constants.CONFIG_FILES[0], (0, _path).extname(_constants.CONFIG_FILES[0]));
  113. const nonJsPath = _findUp.default.sync([
  114. `${configBaseName}.jsx`,
  115. `${configBaseName}.ts`,
  116. `${configBaseName}.tsx`,
  117. `${configBaseName}.json`,
  118. ], {
  119. cwd: dir
  120. });
  121. if (nonJsPath == null ? void 0 : nonJsPath.length) {
  122. throw new Error(`Configuring Next.js via '${(0, _path).basename(nonJsPath)}' is not supported. Please replace the file with 'next.config.js' or 'next.config.mjs'.`);
  123. }
  124. }
  125. // always call assignDefaults to ensure settings like
  126. // reactRoot can be updated correctly even with no next.config.js
  127. const completeConfig = assignDefaults(_configShared.defaultConfig);
  128. completeConfig.configFileName = configFileName;
  129. setHttpAgentOptions(completeConfig.httpAgentOptions);
  130. return completeConfig;
  131. }
  132. function _interopRequireDefault(obj) {
  133. return obj && obj.__esModule ? obj : {
  134. default: obj
  135. };
  136. }
  137. function _getRequireWildcardCache() {
  138. if (typeof WeakMap !== "function") return null;
  139. var cache = new WeakMap();
  140. _getRequireWildcardCache = function() {
  141. return cache;
  142. };
  143. return cache;
  144. }
  145. function _interopRequireWildcard(obj) {
  146. if (obj && obj.__esModule) {
  147. return obj;
  148. }
  149. if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
  150. return {
  151. default: obj
  152. };
  153. }
  154. var cache = _getRequireWildcardCache();
  155. if (cache && cache.has(obj)) {
  156. return cache.get(obj);
  157. }
  158. var newObj = {};
  159. var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
  160. for(var key in obj){
  161. if (Object.prototype.hasOwnProperty.call(obj, key)) {
  162. var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
  163. if (desc && (desc.get || desc.set)) {
  164. Object.defineProperty(newObj, key, desc);
  165. } else {
  166. newObj[key] = obj[key];
  167. }
  168. }
  169. }
  170. newObj.default = obj;
  171. if (cache) {
  172. cache.set(obj, newObj);
  173. }
  174. return newObj;
  175. }
  176. const targets = [
  177. "server",
  178. "serverless",
  179. "experimental-serverless-trace"
  180. ];
  181. const experimentalWarning = (0, _utils).execOnce((configFileName, features)=>{
  182. const s = features.length > 1 ? "s" : "";
  183. Log.warn(_chalk.default.bold(`You have enabled experimental feature${s} (${features.join(", ")}) in ${configFileName}.`));
  184. Log.warn(`Experimental features are not covered by semver, and may cause unexpected or broken application behavior. ` + `Use at your own risk.`);
  185. console.warn();
  186. });
  187. function setHttpAgentOptions(options) {
  188. if (global.__NEXT_HTTP_AGENT) {
  189. // We only need to assign once because we want
  190. // to resuse the same agent for all requests.
  191. return;
  192. }
  193. if (!options) {
  194. throw new Error("Expected config.httpAgentOptions to be an object");
  195. }
  196. global.__NEXT_HTTP_AGENT = new _http.Agent(options);
  197. global.__NEXT_HTTPS_AGENT = new _https.Agent(options);
  198. }
  199. function assignDefaults(userConfig) {
  200. var ref7, ref1, ref2;
  201. const configFileName = userConfig.configFileName;
  202. if (typeof userConfig.exportTrailingSlash !== "undefined") {
  203. console.warn(_chalk.default.yellow.bold("Warning: ") + `The "exportTrailingSlash" option has been renamed to "trailingSlash". Please update your ${configFileName}.`);
  204. if (typeof userConfig.trailingSlash === "undefined") {
  205. userConfig.trailingSlash = userConfig.exportTrailingSlash;
  206. }
  207. delete userConfig.exportTrailingSlash;
  208. }
  209. const config = Object.keys(userConfig).reduce((currentConfig, key)=>{
  210. const value = userConfig[key];
  211. if (value === undefined || value === null) {
  212. return currentConfig;
  213. }
  214. if (key === "experimental" && typeof value === "object") {
  215. const enabledExperiments = [];
  216. // defaultConfig.experimental is predefined and will never be undefined
  217. // This is only a type guard for the typescript
  218. if (_configShared.defaultConfig.experimental) {
  219. for (const featureName of Object.keys(value)){
  220. if (value[featureName] !== _configShared.defaultConfig.experimental[featureName]) {
  221. enabledExperiments.push(featureName);
  222. }
  223. }
  224. }
  225. if (enabledExperiments.length > 0) {
  226. experimentalWarning(configFileName, enabledExperiments);
  227. }
  228. }
  229. if (key === "distDir") {
  230. if (typeof value !== "string") {
  231. throw new Error(`Specified distDir is not a string, found type "${typeof value}"`);
  232. }
  233. const userDistDir = value.trim();
  234. // don't allow public as the distDir as this is a reserved folder for
  235. // public files
  236. if (userDistDir === "public") {
  237. throw new Error(`The 'public' directory is reserved in Next.js and can not be set as the 'distDir'. https://nextjs.org/docs/messages/can-not-output-to-public`);
  238. }
  239. // make sure distDir isn't an empty string as it can result in the provided
  240. // directory being deleted in development mode
  241. if (userDistDir.length === 0) {
  242. throw new Error(`Invalid distDir provided, distDir can not be an empty string. Please remove this config or set it to undefined`);
  243. }
  244. }
  245. if (key === "pageExtensions") {
  246. if (!Array.isArray(value)) {
  247. throw new Error(`Specified pageExtensions is not an array of strings, found "${value}". Please update this config or remove it.`);
  248. }
  249. if (!value.length) {
  250. throw new Error(`Specified pageExtensions is an empty array. Please update it with the relevant extensions or remove it.`);
  251. }
  252. value.forEach((ext)=>{
  253. if (typeof ext !== "string") {
  254. throw new Error(`Specified pageExtensions is not an array of strings, found "${ext}" of type "${typeof ext}". Please update this config or remove it.`);
  255. }
  256. });
  257. }
  258. if (!!value && value.constructor === Object) {
  259. currentConfig[key] = {
  260. ..._configShared.defaultConfig[key],
  261. ...Object.keys(value).reduce((c, k)=>{
  262. const v = value[k];
  263. if (v !== undefined && v !== null) {
  264. c[k] = v;
  265. }
  266. return c;
  267. }, {})
  268. };
  269. } else {
  270. currentConfig[key] = value;
  271. }
  272. return currentConfig;
  273. }, {});
  274. const result = {
  275. ..._configShared.defaultConfig,
  276. ...config
  277. };
  278. if (typeof result.assetPrefix !== "string") {
  279. throw new Error(`Specified assetPrefix is not a string, found type "${typeof result.assetPrefix}" https://nextjs.org/docs/messages/invalid-assetprefix`);
  280. }
  281. if (typeof result.basePath !== "string") {
  282. throw new Error(`Specified basePath is not a string, found type "${typeof result.basePath}"`);
  283. }
  284. if (result.basePath !== "") {
  285. if (result.basePath === "/") {
  286. throw new Error(`Specified basePath /. basePath has to be either an empty string or a path prefix"`);
  287. }
  288. if (!result.basePath.startsWith("/")) {
  289. throw new Error(`Specified basePath has to start with a /, found "${result.basePath}"`);
  290. }
  291. if (result.basePath !== "/") {
  292. var ref3;
  293. if (result.basePath.endsWith("/")) {
  294. throw new Error(`Specified basePath should not end with /, found "${result.basePath}"`);
  295. }
  296. if (result.assetPrefix === "") {
  297. result.assetPrefix = result.basePath;
  298. }
  299. if (((ref3 = result.amp) == null ? void 0 : ref3.canonicalBase) === "") {
  300. result.amp.canonicalBase = result.basePath;
  301. }
  302. }
  303. }
  304. if (result == null ? void 0 : result.images) {
  305. var ref4, ref5;
  306. const images = result.images;
  307. if (typeof images !== "object") {
  308. throw new Error(`Specified images should be an object received ${typeof images}.\nSee more info here: https://nextjs.org/docs/messages/invalid-images-config`);
  309. }
  310. if (images.domains) {
  311. var ref6;
  312. if (!Array.isArray(images.domains)) {
  313. throw new Error(`Specified images.domains should be an Array received ${typeof images.domains}.\nSee more info here: https://nextjs.org/docs/messages/invalid-images-config`);
  314. }
  315. // static images are automatically prefixed with assetPrefix
  316. // so we need to ensure _next/image allows downloading from
  317. // this resource
  318. if ((ref6 = config.assetPrefix) == null ? void 0 : ref6.startsWith("http")) {
  319. images.domains.push(new URL(config.assetPrefix).hostname);
  320. }
  321. if (images.domains.length > 50) {
  322. throw new Error(`Specified images.domains exceeds length of 50, received length (${images.domains.length}), please reduce the length of the array to continue.\nSee more info here: https://nextjs.org/docs/messages/invalid-images-config`);
  323. }
  324. const invalid = images.domains.filter((d)=>typeof d !== "string");
  325. if (invalid.length > 0) {
  326. throw new Error(`Specified images.domains should be an Array of strings received invalid values (${invalid.join(", ")}).\nSee more info here: https://nextjs.org/docs/messages/invalid-images-config`);
  327. }
  328. }
  329. const remotePatterns = result == null ? void 0 : (ref4 = result.images) == null ? void 0 : ref4.remotePatterns;
  330. if (remotePatterns) {
  331. if (!Array.isArray(remotePatterns)) {
  332. throw new Error(`Specified images.remotePatterns should be an Array received ${typeof remotePatterns}.\nSee more info here: https://nextjs.org/docs/messages/invalid-images-config`);
  333. }
  334. if (remotePatterns.length > 50) {
  335. throw new Error(`Specified images.remotePatterns exceeds length of 50, received length (${remotePatterns.length}), please reduce the length of the array to continue.\nSee more info here: https://nextjs.org/docs/messages/invalid-images-config`);
  336. }
  337. const validProps = new Set([
  338. "protocol",
  339. "hostname",
  340. "pathname",
  341. "port"
  342. ]);
  343. const requiredProps = [
  344. "hostname"
  345. ];
  346. const invalidPatterns = remotePatterns.filter((d)=>!d || typeof d !== "object" || Object.entries(d).some(([k, v])=>!validProps.has(k) || typeof v !== "string") || requiredProps.some((k)=>!(k in d)));
  347. if (invalidPatterns.length > 0) {
  348. throw new Error(`Invalid images.remotePatterns values:\n${invalidPatterns.map((item)=>JSON.stringify(item)).join("\n")}\n\nremotePatterns value must follow format { protocol: 'https', hostname: 'example.com', port: '', pathname: '/imgs/**' }.\nSee more info here: https://nextjs.org/docs/messages/invalid-images-config`);
  349. }
  350. }
  351. if (images.deviceSizes) {
  352. const { deviceSizes } = images;
  353. if (!Array.isArray(deviceSizes)) {
  354. throw new Error(`Specified images.deviceSizes should be an Array received ${typeof deviceSizes}.\nSee more info here: https://nextjs.org/docs/messages/invalid-images-config`);
  355. }
  356. if (deviceSizes.length > 25) {
  357. throw new Error(`Specified images.deviceSizes exceeds length of 25, received length (${deviceSizes.length}), please reduce the length of the array to continue.\nSee more info here: https://nextjs.org/docs/messages/invalid-images-config`);
  358. }
  359. const invalid = deviceSizes.filter((d)=>{
  360. return typeof d !== "number" || d < 1 || d > 10000;
  361. });
  362. if (invalid.length > 0) {
  363. throw new Error(`Specified images.deviceSizes should be an Array of numbers that are between 1 and 10000, received invalid values (${invalid.join(", ")}).\nSee more info here: https://nextjs.org/docs/messages/invalid-images-config`);
  364. }
  365. }
  366. if (images.imageSizes) {
  367. const { imageSizes } = images;
  368. if (!Array.isArray(imageSizes)) {
  369. throw new Error(`Specified images.imageSizes should be an Array received ${typeof imageSizes}.\nSee more info here: https://nextjs.org/docs/messages/invalid-images-config`);
  370. }
  371. if (imageSizes.length > 25) {
  372. throw new Error(`Specified images.imageSizes exceeds length of 25, received length (${imageSizes.length}), please reduce the length of the array to continue.\nSee more info here: https://nextjs.org/docs/messages/invalid-images-config`);
  373. }
  374. const invalid = imageSizes.filter((d)=>{
  375. return typeof d !== "number" || d < 1 || d > 10000;
  376. });
  377. if (invalid.length > 0) {
  378. throw new Error(`Specified images.imageSizes should be an Array of numbers that are between 1 and 10000, received invalid values (${invalid.join(", ")}).\nSee more info here: https://nextjs.org/docs/messages/invalid-images-config`);
  379. }
  380. }
  381. if (!images.loader) {
  382. images.loader = "default";
  383. }
  384. if (!_imageConfig.VALID_LOADERS.includes(images.loader)) {
  385. throw new Error(`Specified images.loader should be one of (${_imageConfig.VALID_LOADERS.join(", ")}), received invalid value (${images.loader}).\nSee more info here: https://nextjs.org/docs/messages/invalid-images-config`);
  386. }
  387. if (images.loader !== "default" && images.loader !== "custom" && images.path === _imageConfig.imageConfigDefault.path) {
  388. throw new Error(`Specified images.loader property (${images.loader}) also requires images.path property to be assigned to a URL prefix.\nSee more info here: https://nextjs.org/docs/api-reference/next/image#loader-configuration`);
  389. }
  390. // Append trailing slash for non-default loaders and when trailingSlash is set
  391. if (images.path) {
  392. if (images.loader !== "default" && images.path[images.path.length - 1] !== "/" || result.trailingSlash) {
  393. images.path += "/";
  394. }
  395. }
  396. if (images.path === _imageConfig.imageConfigDefault.path && result.basePath) {
  397. images.path = `${result.basePath}${images.path}`;
  398. }
  399. if (images.minimumCacheTTL && (!Number.isInteger(images.minimumCacheTTL) || images.minimumCacheTTL < 0)) {
  400. throw new Error(`Specified images.minimumCacheTTL should be an integer 0 or more received (${images.minimumCacheTTL}).\nSee more info here: https://nextjs.org/docs/messages/invalid-images-config`);
  401. }
  402. if (images.formats) {
  403. const { formats } = images;
  404. if (!Array.isArray(formats)) {
  405. throw new Error(`Specified images.formats should be an Array received ${typeof formats}.\nSee more info here: https://nextjs.org/docs/messages/invalid-images-config`);
  406. }
  407. if (formats.length < 1 || formats.length > 2) {
  408. throw new Error(`Specified images.formats must be length 1 or 2, received length (${formats.length}), please reduce the length of the array to continue.\nSee more info here: https://nextjs.org/docs/messages/invalid-images-config`);
  409. }
  410. const invalid = formats.filter((f)=>{
  411. return f !== "image/avif" && f !== "image/webp";
  412. });
  413. if (invalid.length > 0) {
  414. throw new Error(`Specified images.formats should be an Array of mime type strings, received invalid values (${invalid.join(", ")}).\nSee more info here: https://nextjs.org/docs/messages/invalid-images-config`);
  415. }
  416. }
  417. if (typeof images.dangerouslyAllowSVG !== "undefined" && typeof images.dangerouslyAllowSVG !== "boolean") {
  418. throw new Error(`Specified images.dangerouslyAllowSVG should be a boolean received (${images.dangerouslyAllowSVG}).\nSee more info here: https://nextjs.org/docs/messages/invalid-images-config`);
  419. }
  420. if (typeof images.contentSecurityPolicy !== "undefined" && typeof images.contentSecurityPolicy !== "string") {
  421. throw new Error(`Specified images.contentSecurityPolicy should be a string received (${images.contentSecurityPolicy}).\nSee more info here: https://nextjs.org/docs/messages/invalid-images-config`);
  422. }
  423. const unoptimized = result == null ? void 0 : (ref5 = result.images) == null ? void 0 : ref5.unoptimized;
  424. if (typeof unoptimized !== "undefined" && typeof unoptimized !== "boolean") {
  425. throw new Error(`Specified images.unoptimized should be a boolean, received (${unoptimized}).\nSee more info here: https://nextjs.org/docs/messages/invalid-images-config`);
  426. }
  427. }
  428. if (result.webpack5 === false) {
  429. throw new Error(`Webpack 4 is no longer supported in Next.js. Please upgrade to webpack 5 by removing "webpack5: false" from ${configFileName}. https://nextjs.org/docs/messages/webpack5`);
  430. }
  431. if (result.experimental && "swcMinify" in result.experimental) {
  432. Log.warn(`\`swcMinify\` has been moved out of \`experimental\`. Please update your ${configFileName} file accordingly.`);
  433. result.swcMinify = result.experimental.swcMinify;
  434. }
  435. if (result.experimental && "relay" in result.experimental) {
  436. Log.warn(`\`relay\` has been moved out of \`experimental\` and into \`compiler\`. Please update your ${configFileName} file accordingly.`);
  437. result.compiler = result.compiler || {};
  438. result.compiler.relay = result.experimental.relay;
  439. }
  440. if (result.experimental && "styledComponents" in result.experimental) {
  441. Log.warn(`\`styledComponents\` has been moved out of \`experimental\` and into \`compiler\`. Please update your ${configFileName} file accordingly.`);
  442. result.compiler = result.compiler || {};
  443. result.compiler.styledComponents = result.experimental.styledComponents;
  444. }
  445. if (result.experimental && "emotion" in result.experimental) {
  446. Log.warn(`\`emotion\` has been moved out of \`experimental\` and into \`compiler\`. Please update your ${configFileName} file accordingly.`);
  447. result.compiler = result.compiler || {};
  448. result.compiler.emotion = result.experimental.emotion;
  449. }
  450. if (result.experimental && "reactRemoveProperties" in result.experimental) {
  451. Log.warn(`\`reactRemoveProperties\` has been moved out of \`experimental\` and into \`compiler\`. Please update your ${configFileName} file accordingly.`);
  452. result.compiler = result.compiler || {};
  453. result.compiler.reactRemoveProperties = result.experimental.reactRemoveProperties;
  454. }
  455. if (result.experimental && "removeConsole" in result.experimental) {
  456. Log.warn(`\`removeConsole\` has been moved out of \`experimental\` and into \`compiler\`. Please update your ${configFileName} file accordingly.`);
  457. result.compiler = result.compiler || {};
  458. result.compiler.removeConsole = result.experimental.removeConsole;
  459. }
  460. if ((ref7 = result.experimental) == null ? void 0 : ref7.swcMinifyDebugOptions) {
  461. Log.warn("SWC minify debug option specified. This option is for debugging minifier issues and will be removed once SWC minifier is stable.");
  462. }
  463. if (result.experimental.outputStandalone) {
  464. Log.warn(`experimental.outputStandalone has been renamed to "output: 'standalone'", please move the config.`);
  465. result.output = "standalone";
  466. }
  467. if (((ref1 = result.experimental) == null ? void 0 : ref1.outputFileTracingRoot) && !(0, _path).isAbsolute(result.experimental.outputFileTracingRoot)) {
  468. result.experimental.outputFileTracingRoot = (0, _path).resolve(result.experimental.outputFileTracingRoot);
  469. Log.warn(`experimental.outputFileTracingRoot should be absolute, using: ${result.experimental.outputFileTracingRoot}`);
  470. }
  471. if (result.output === "standalone" && !result.outputFileTracing) {
  472. Log.warn(`"output: 'standalone'" requires outputFileTracing not be disabled please enable it to leverage the standalone build`);
  473. result.output = undefined;
  474. }
  475. // TODO: Change defaultConfig type to NextConfigComplete
  476. // so we don't need "!" here.
  477. setHttpAgentOptions(result.httpAgentOptions || _configShared.defaultConfig.httpAgentOptions);
  478. if (result.i18n) {
  479. const { i18n } = result;
  480. const i18nType = typeof i18n;
  481. if (i18nType !== "object") {
  482. throw new Error(`Specified i18n should be an object received ${i18nType}.\nSee more info here: https://nextjs.org/docs/messages/invalid-i18n-config`);
  483. }
  484. if (!Array.isArray(i18n.locales)) {
  485. throw new Error(`Specified i18n.locales should be an Array received ${typeof i18n.locales}.\nSee more info here: https://nextjs.org/docs/messages/invalid-i18n-config`);
  486. }
  487. if (i18n.locales.length > 100) {
  488. Log.warn(`Received ${i18n.locales.length} i18n.locales items which exceeds the recommended max of 100.\nSee more info here: https://nextjs.org/docs/advanced-features/i18n-routing#how-does-this-work-with-static-generation`);
  489. }
  490. const defaultLocaleType = typeof i18n.defaultLocale;
  491. if (!i18n.defaultLocale || defaultLocaleType !== "string") {
  492. throw new Error(`Specified i18n.defaultLocale should be a string.\nSee more info here: https://nextjs.org/docs/messages/invalid-i18n-config`);
  493. }
  494. if (typeof i18n.domains !== "undefined" && !Array.isArray(i18n.domains)) {
  495. throw new Error(`Specified i18n.domains must be an array of domain objects e.g. [ { domain: 'example.fr', defaultLocale: 'fr', locales: ['fr'] } ] received ${typeof i18n.domains}.\nSee more info here: https://nextjs.org/docs/messages/invalid-i18n-config`);
  496. }
  497. if (i18n.domains) {
  498. const invalidDomainItems = i18n.domains.filter((item)=>{
  499. var ref;
  500. if (!item || typeof item !== "object") return true;
  501. if (!item.defaultLocale) return true;
  502. if (!item.domain || typeof item.domain !== "string") return true;
  503. const defaultLocaleDuplicate = (ref = i18n.domains) == null ? void 0 : ref.find((altItem)=>altItem.defaultLocale === item.defaultLocale && altItem.domain !== item.domain);
  504. if (defaultLocaleDuplicate) {
  505. console.warn(`Both ${item.domain} and ${defaultLocaleDuplicate.domain} configured the defaultLocale ${item.defaultLocale} but only one can. Change one item's default locale to continue`);
  506. return true;
  507. }
  508. let hasInvalidLocale = false;
  509. if (Array.isArray(item.locales)) {
  510. for (const locale of item.locales){
  511. if (typeof locale !== "string") hasInvalidLocale = true;
  512. for (const domainItem of i18n.domains || []){
  513. if (domainItem === item) continue;
  514. if (domainItem.locales && domainItem.locales.includes(locale)) {
  515. console.warn(`Both ${item.domain} and ${domainItem.domain} configured the locale (${locale}) but only one can. Remove it from one i18n.domains config to continue`);
  516. hasInvalidLocale = true;
  517. break;
  518. }
  519. }
  520. }
  521. }
  522. return hasInvalidLocale;
  523. });
  524. if (invalidDomainItems.length > 0) {
  525. throw new Error(`Invalid i18n.domains values:\n${invalidDomainItems.map((item)=>JSON.stringify(item)).join("\n")}\n\ndomains value must follow format { domain: 'example.fr', defaultLocale: 'fr', locales: ['fr'] }.\nSee more info here: https://nextjs.org/docs/messages/invalid-i18n-config`);
  526. }
  527. }
  528. if (!Array.isArray(i18n.locales)) {
  529. throw new Error(`Specified i18n.locales must be an array of locale strings e.g. ["en-US", "nl-NL"] received ${typeof i18n.locales}.\nSee more info here: https://nextjs.org/docs/messages/invalid-i18n-config`);
  530. }
  531. const invalidLocales = i18n.locales.filter((locale)=>typeof locale !== "string");
  532. if (invalidLocales.length > 0) {
  533. throw new Error(`Specified i18n.locales contains invalid values (${invalidLocales.map(String).join(", ")}), locales must be valid locale tags provided as strings e.g. "en-US".\n` + `See here for list of valid language sub-tags: http://www.iana.org/assignments/language-subtag-registry/language-subtag-registry`);
  534. }
  535. if (!i18n.locales.includes(i18n.defaultLocale)) {
  536. throw new Error(`Specified i18n.defaultLocale should be included in i18n.locales.\nSee more info here: https://nextjs.org/docs/messages/invalid-i18n-config`);
  537. }
  538. const normalizedLocales = new Set();
  539. const duplicateLocales = new Set();
  540. i18n.locales.forEach((locale)=>{
  541. const localeLower = locale.toLowerCase();
  542. if (normalizedLocales.has(localeLower)) {
  543. duplicateLocales.add(locale);
  544. }
  545. normalizedLocales.add(localeLower);
  546. });
  547. if (duplicateLocales.size > 0) {
  548. throw new Error(`Specified i18n.locales contains the following duplicate locales:\n` + `${[
  549. ...duplicateLocales
  550. ].join(", ")}\n` + `Each locale should be listed only once.\n` + `See more info here: https://nextjs.org/docs/messages/invalid-i18n-config`);
  551. }
  552. // make sure default Locale is at the front
  553. i18n.locales = [
  554. i18n.defaultLocale,
  555. ...i18n.locales.filter((locale)=>locale !== i18n.defaultLocale),
  556. ];
  557. const localeDetectionType = typeof i18n.localeDetection;
  558. if (localeDetectionType !== "boolean" && localeDetectionType !== "undefined") {
  559. throw new Error(`Specified i18n.localeDetection should be undefined or a boolean received ${localeDetectionType}.\nSee more info here: https://nextjs.org/docs/messages/invalid-i18n-config`);
  560. }
  561. }
  562. if ((ref2 = result.devIndicators) == null ? void 0 : ref2.buildActivityPosition) {
  563. const { buildActivityPosition } = result.devIndicators;
  564. const allowedValues = [
  565. "top-left",
  566. "top-right",
  567. "bottom-left",
  568. "bottom-right",
  569. ];
  570. if (!allowedValues.includes(buildActivityPosition)) {
  571. throw new Error(`Invalid "devIndicator.buildActivityPosition" provided, expected one of ${allowedValues.join(", ")}, received ${buildActivityPosition}`);
  572. }
  573. }
  574. return result;
  575. }
  576. //# sourceMappingURL=config.js.map