Skip to content

react-app-alias-ex is not a drop-in replacement for react-app-alias #95

@bryanculver

Description

@bryanculver

When using react-app-alias-ex to allow outside of root packages (a unique aspect of our setup) Jest throws resolver errors:

 FAIL  src/views/__tests__/BSListViewTemplate.test.js
  ● Test suite failed to run

    Cannot find module 'semver' from 'node_modules/jest-snapshot/build/InlineSnapshots.js'

    Require stack:
      node_modules/jest-snapshot/build/InlineSnapshots.js
      node_modules/jest-snapshot/build/State.js
      node_modules/jest-snapshot/build/index.js
      node_modules/jest-circus/build/legacy-code-todo-rewrite/jestAdapterInit.js

      at Resolver.resolveModule (node_modules/jest-resolve/build/resolver.js:324:11)

But switching back to react-app-alias and temporarily commenting out our external packages works as expected.

Config files:

// jsconfig.paths.js
{
    "compilerOptions": {
        "baseUrl": ".",
        "paths": {
            "@utils/*": ["src/utils/*"],
            "@constants/*": ["src/constants/*"],
            "@views/*": ["src/views/*"],
            "@components/*": ["src/components/*"],
            "@layouts/*": ["src/components/layouts/*"],
            "@common/*": ["src/components/common/*"],
            "@core/*": ["src/components/core/*"],
            "@example_plugin/*": [
                "../../examples/example_plugin/example_plugin/ui/*"
            ]
        }
    }
}
// jsconfig.js
{
    "extends": "./jsconfig.paths.json",
    "compilerOptions": {}
}
// craco.config.js

const { CracoAliasPlugin } = require("react-app-alias");

module.exports = {
    plugins: [
        {
            plugin: CracoAliasPlugin,
        },
    ],

    webpack: {
        configure: (webpackConfig, { env, paths }) => {
        
            webpackConfig.output.filename = "static/js/[name].js"; 
            webpackConfig.output.assetModuleFilename = "static/media/[name].[ext]";
            webpackConfig.output.chunkFilename = "static/js/[id]-[chunkhash].js";

            webpackConfig.devtool = "eval-cheap-module-source-map";

            webpackConfig.plugins[5].options.filename = "static/css/[name].css";
            return webpackConfig;
        },
    },
};

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions