Skip to content

[NextJS] next/font" requires SWC although Babel is being used due to a custom babel config being present #190

@ebitogu

Description

@ebitogu

I am not sure what maybe wrong as I am basically copying over the existing sample code for NextJS using app router on NextJS 14.

Here is the content of my .babelrc.js file:

const path = require('path');

module.exports = {
    presets: ['next/babel'],
    plugins: [
        [
            '@stylexjs/babel-plugin',
            {
                dev: process.env.NODE_ENV === 'development',
                runtimeInjection: false,
                genConditionalClasses: true,
                treeshakeCompensation: true,
                unstable_moduleResolution: {
                    type: 'commonJS',
                    rootDir: path.join(__dirname, '../..'),
                },
            },
        ],
    ],
};

and here is my next.config.js file

const withNextIntl = require('next-intl/plugin')();
const stylexPlugin = require('@stylexjs/nextjs-plugin');
const babelrc = require('./.babelrc.js');
const plugins = babelrc.plugins;
const [_name, options] = plugins.find(
    (plugin) => Array.isArray(plugin) && plugin[0] === '@stylexjs/babel-plugin',
);
const rootDir = options.unstable_moduleResolution.rootDir ?? __dirname;

module.exports = withNextIntl(stylexPlugin({
    rootDir,
    useCSSLayers: true,
})({}));

Unfortunately, anytime I start the app I keep getting this error:

Syntax error: "next/font" requires SWC although Babel is being used due to a custom babel config being present.
Read more: https://nextjs.org/docs/messages/babel-font-loader-conflict

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingwontfixThis will not be worked on

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions