From e1c587ddf873f79c6198e38a7dbbfa57c6168034 Mon Sep 17 00:00:00 2001 From: Brijesh Bittu Date: Wed, 11 Sep 2024 14:48:57 +0530 Subject: [PATCH] [nextjs] Move the import startsWith next check at end (#228) Co-authored-by: Brijesh Bittu --- .../pigment-css-nextjs-plugin/src/index.ts | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) 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); }