Search code examples
javascriptreactjsyarnpkgyarn-workspaces

Yarn Workspaces, workspace does not emit errors or warnings


I have followed the following post in order to create a monorepo using yarn workspaces and craco. It works really well except one thing: the errors/warnings of the common (components )library are not emitted to the console. The structure is very simple:

monorepo
|-packages
  |-components
  |-fe

Fe is the main webApp that uses the components library. The FE emits all warnings correctly, components does not.

How to make the shared component emit warnings/errors?

Updated:

Steps to reproduce in this repo: https://github.com/sofoklisM/my-monorepo.git


Solution

  • What you need to change is the context option of the underlying ESLint Webpack plugin that is used by Create React App. In this case I changed the context of ESLint to the root of the monorepo (yarn workspace root).

    Here is an updated craco.config.js that should do the trick:

    // craco.config.js
    const path = require("path");
    const { getLoader, loaderByName } = require("@craco/craco");
    const { getPlugin, pluginByName } = require("@craco/craco/lib/webpack-plugins")
    const absolutePath = path.join(__dirname, "../components");
    module.exports = {
      webpack: {
        alias: {},
        plugins: [],
        configure: (webpackConfig, { env, paths }) => {
          const { isFound, match } = getLoader(
            webpackConfig,
            loaderByName("babel-loader")
          );
          if (isFound) {
            const include = Array.isArray(match.loader.include)
              ? match.loader.include
              : [match.loader.include];
            match.loader.include = include.concat([absolutePath]);
          }
    
          // Change context of ESLint Webpack Plugin
          const { match: eslintPlugin } = getPlugin(webpackConfig, pluginByName("ESLintWebpackPlugin"));
          eslintPlugin.options['context'] = path.join(__dirname, "../..");
    
          return webpackConfig;
        }
      }
    };
    

    I've also made an updated fork of your reproduction repo here: https://github.com/ofhouse/stackoverflow-65447779