Skip to content

Bug: Entry resolves before async resolve call the callback function #3641

Closed

Description

@hansl

This is a regression from beta.25 or higher.

Expected Behaviour

The resolve event should be asynchronous and need to wait for all plugins callbacks before continuing the resolution, but doesn't (at least for the entry).

Actual Behaviour

Right now, webpack does not wait for all resolve handlers before continuing the resolution.

The following Webpack configuration (custom plugin) will finish the bundle, THEN wait 10 seconds for the resolve to finish.

module.exports = {
  resolve: {
    extensions: ['.js']
  },
  entry: './entry.js',
  output: {
    path: './dist',
    publicPath: 'dist/',
    filename: 'app.main.js'
  },
  plugins: [
    new function () {
      this.apply = function (compiler) {
        compiler.plugin('after-resolvers', function (compiler) {
          compiler.resolvers.normal.plugin('resolve', function (request, cb) {
            setTimeout(cb, 10000);
          });
        });
      };
    },
  ]
};

Activity

  1. sokra commented on Dec 30, 2016

    @sokra
    Member

    It's correct this way.

    with your resolve plugin you add an alternative how to resolve modules. Because you add it after the original resolvers the original resolving algorithm has higher priority. From logical point of view your plugin is only used if the original algorithm is not successful. For performance reasons hooks are not executed in sequence but parallel (see applyPluginsParallelBailResult in tapable) with a bailing callback handler. This means if the first plugin (the original resolving algorithm) returns a result the result of the second plugin is ignored and it doesn't need to wait for it.

    You can try to resolve a request that can't be resolved by the original algorithm (like ./eeeentry.js) and it should wait for your plugin to finish.

  2. hansl commented on Jan 7, 2017

    @hansl
    Author

    So you're saying the best way for me to wait for my entry point's dependency (because TypeScript will error if I compile too early) to be ready is to either rename the entry point to something that doesn't exist, or hook up before-resolve?

    I understand how and why you do it, but isn't there a way to shut the original resolver for certain filetypes?

  3. timse commented on Mar 28, 2017

    @timse
    Contributor

    As there seams to be nothing happening anymore here, I will close this for now.
    Feel free to reopen, if you think this needs to be resolved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions