Sequence of `resolve.alias` keys can cause import failure

Do you want to request a feature or report a bug?

Bug

What is the current behavior?

When using the alias key to re-map imports, if the more general alias appears above a more specific alias in the object, imports to the more specific module will fail.

We recently published a new version of RxJS and published a re-mapping file to point deep imports to their ESM build sources rather than CJS. Came across this issue debugging some user issues.

If the current behavior is a bug, please provide the steps to reproduce.

Created a reproduction here. Clone repo on webpack_alias_failure branch, go to webpack directory, yarn install, yarn webpack.

Comments show how to “fix” the issue in webpack.config.js.

What is the expected behavior?

alias is an object. Sequence of keys should not be depended up on for behavior.

If this is a feature request, what is motivation or use case for changing the behavior?

Please mention other relevant information such as the browser version, Node.js version, webpack version and Operating System.

Author: Fantashit

1 thought on “Sequence of `resolve.alias` keys can cause import failure

  1. They are matched in order.

    These configuration is ambiguous:

        alias: {
          "./utils": "./genericUtils/index.js",
          "./utils/sum": "./genericUtils/sum.js"
        }

    You can use this one instead, which is not ambiguous:

        alias: {
          "./utils$": "./genericUtils/index.js",
          "./utils/sum": "./genericUtils/sum.js"
        }

Comments are closed.