Skip to content

Commit

Permalink
fix(next): Fix breaking changes in 14.1
Browse files Browse the repository at this point in the history
  • Loading branch information
NiGhTTraX committed Sep 2, 2024
1 parent 02ecdd1 commit f1876c0
Showing 1 changed file with 5 additions and 40 deletions.
45 changes: 5 additions & 40 deletions apps/nextjs/next.config.js
Original file line number Diff line number Diff line change
@@ -1,47 +1,12 @@
const isNext12 = (config) => !!config.module.rules.find((rule) => rule.oneOf);

const updateNextGreaterThan12Config = (config) => {
const oneOfRule = config.module.rules.find((rule) => rule.oneOf);

// Next 12 has multiple TS loaders, and we need to update all of them.
const tsRules = oneOfRule.oneOf.filter(
(rule) => rule.test && rule.test.toString().includes("tsx|ts")
);

tsRules.forEach((rule) => {
// eslint-disable-next-line no-param-reassign
rule.include = undefined;
});

return config;
};

const updateNextLessThan12Config = (config) => {
// Next < 12 uses a single Babel loader.
const tsRule = config.module.rules.find(
(rule) => rule.test && rule.test.toString().includes("tsx|ts")
);

tsRule.include = undefined;
tsRule.exclude = /node_modules/;

return config;
};

module.exports = {
/**
* You can use the following experimental flag if you're on Next >= 10.1.0.
* Note that this can change/break without warning.
* This will become the default eventually.
*
* @see https://github.com/vercel/next.js/discussions/26420#discussioncomment-6568785
* @see https://github.com/vercel/next.js/pull/22867
*/
// experimental: {
// externalDir: true,
// },
webpack: (config) => {
if (isNext12(config)) {
return updateNextGreaterThan12Config(config);
}

return updateNextLessThan12Config(config);
experimental: {
externalDir: true,
},
};

0 comments on commit f1876c0

Please sign in to comment.