Next/15/Refactor Experimental.ServerComponentsExternalPackages To ServerExternalPackages

/icons/calendar.svg

Last update

Aug 29, 2024

Refactor experimental.serverComponentsExternalPackages to serverExternalPackages

This codemod refactors the next.config.js file to replace the deprecated experimental.serverComponentsExternalPackages option with the stable serverExternalPackages, improving configuration clarity and maintainability.

  • Find Configuration Object: Identifies the nextConfig object in the code.

  • Property Check: Ensures the presence of the experimental object and its properties that need updating.

  • Move and Rename Property: Moves serverComponentsExternalPackages from the experimental object to the root level and renames it to serverExternalPackages.

  • Clean Up: Removes the experimental object if it becomes empty after the migration.

Before

/** @type {import('next').NextConfig} */
const nextConfig = {
experimental: {
serverComponentsExternalPackages: ["package-name"],
},
};
module.exports = nextConfig;

After

/** @type {import('next').NextConfig} */
const nextConfig = {
serverExternalPackages: ["package-name"],
};
module.exports = nextConfig;

Build custom codemods

Use AI-powered codemod studio and automate undifferentiated tasks for yourself, colleagues or the community

background illustrationGet Started Now