diff --git a/packages/pigment-css-nextjs-plugin/src/index.ts b/packages/pigment-css-nextjs-plugin/src/index.ts index ef4df07a..04d9576f 100644 --- a/packages/pigment-css-nextjs-plugin/src/index.ts +++ b/packages/pigment-css-nextjs-plugin/src/index.ts @@ -61,13 +61,7 @@ export function withPigment(nextConfig: NextConfig, pigmentConfig?: PigmentOptio if (what.startsWith('__barrel_optimize__')) { return require.resolve('../next-font'); } - // Need to point to the react from node_modules during eval time. - // Otherwise, next makes it point to its own version of react that - // has a lot of RSC specific logic which is not actually needed. - if (what.startsWith('@babel') || what.startsWith('react') || what.startsWith('next')) { - return require.resolve(what); - } - if (what === 'next/image') { + if (what === 'next/image' || what === 'next/link') { return require.resolve('../next-image'); } if (what.startsWith('next/font')) { @@ -76,6 +70,17 @@ export function withPigment(nextConfig: NextConfig, pigmentConfig?: PigmentOptio if (what.startsWith('@emotion/styled') || what.startsWith('styled-components')) { return require.resolve('../third-party-styled'); } + // Need to point to the react from node_modules during eval time. + // Otherwise, next makes it point to its own version of react that + // has a lot of RSC specific logic which is not actually needed. + if ( + what === 'react' || + what.startsWith('react-dom/') || + what.startsWith('@babel/') || + what.startsWith('next/') + ) { + return require.resolve(what); + } if (asyncResolve) { return asyncResolve(what, importer, stack); }