Skip to content

Babel configuration not being applied to files outside app directory after upgrade 9.3.1 -> 9.4.4 #13980

Closed
@dminkovsky

Description

@dminkovsky

Bug report

Describe the bug

I have a yarn workspace project layout like:

|- common/ (shared by mobile and web)
|- web/ (Next.js project)
|- mobile/ (custom Webpack built SPA, not relevant)
|- babel.config.js

My babel configuration requires:

  • The styled-components plugin,
  • Imports from common to be transpiled in my Next.js build.

So I have the following next.config.js:

/* global __dirname */

const path = require('path');
const withPlugins = require('next-compose-plugins');
const withTM = require('next-transpile-modules')([
    '@glidejs/glide',
    'common',
]);

module.exports = withPlugins([withTM], {
    webpack: (config, options) => {
        // Seems to no longer be necessary with 9.4?
        config.module.rules.forEach(rule => {
            if (
                rule.use &&
                rule.use.loader === 'next-babel-loader'
            ) {
               // Set Babel root to workspace root, so config applies to workspace modules.   
               rule.use.options.root = resolve('..');
               // But use the local config
               rule.use.options.configFile = resolve('.babelrc'); 
            }
        });
        return config;
    },
});

function resolve() {
    return path.resolve.apply(path, [__dirname, ...arguments]);
}

  • Using the transpile modules plugin allows transpiling workspacem modules.
  • Setting rule.use.options.root = resolve('..'); sets the babel root to the workspace root, which allows using babel.config.js as global config and which has the following content:
module.exports = {
    presets: ["next/babel"],
    plugins: [
        ["babel-plugin-styled-components"],
        "@babel/plugin-proposal-optional-chaining"
    ],
}

After upgrading 9.3.1 to 9.4.4, this config breaks for some reason. In my browser console I see errors which indicate the styled components plugin is not being used:

Warning: Prop className did not match. Server: "CompleteAccount__Head-sc-1dzpt9v-0 egJJdE" Client: "sc-jWBwVP yNfFn"

Expected

I would expect that as with 9.3.1, the 9.4.4 webpack configuration would allow using the workspace-wide, common babel config in babel.config.js.

Metadata

Metadata

Assignees

No one assigned

    Labels

    UpstreamRelated to using Next.js with a third-party dependency. (e.g., React, UI/icon libraries, etc.).

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions