question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Dependencies are bundled in the wrong order

See original GitHub issue

If you create a new default typescript project, add bootstrap and jQuery, then apply the dependency to the bundle as documented it works:

"dependencies": [
  "jquery",
  {
    "name": "bootstrap",
    "path": "../node_modules/bootstrap/dist",
    "main": "js/bootstrap.min",
    "deps": ["jquery"],
    "exports": "$"
  }
]

Now, remove jasmine from the project (don’t ask, I had to experiment to find the error in my project) and the vendor bundle contains bootstrap before jQuery, so the application fails on startup.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:3
  • Comments:23 (10 by maintainers)

github_iconTop GitHub Comments

1reaction
alpoxcommented, Dec 7, 2016

I may have some input to this one.

I wrote a fix for a deeper source location possibility (src file not in root folder): https://github.com/aurelia/cli/pull/427 During the progress i found some strange things happening to the dependency load order too - since i do some asynchronous folder lookups, the dependency order came wrong in most cases.

I tracked this issue down and found the bad-boy. (Fixed it also in the pull request) The issue seems to have its root in the aurelia-cli/lib/build/bundle.js file in the code:

static create(bundler, config) {
    let bundle = new exports.Bundle(bundler, config);
    let dependencies = config.dependencies || [];

    return Promise.all(
      dependencies
        .filter(x => bundler.itemIncludedInBuild(x))
        .map(dependency => bundler.configureDependency(dependency)
        .then(description => bundle.addDependency(description)))
    ).then(() => bundle);
  }

bundler.configureDependency is an asynchronous task. since all configureDependency get called at one point and are waiting for finish, the promises are able to resolve in different order than they occur in the dependencies array and are therefore also added to the bundle in a different order.

I fixed this with the following:

 static create(bundler, config) {
    let bundle = new exports.Bundle(bundler, config);
    let dependencies = config.dependencies || [];

    return Promise.all(
      dependencies
        .filter(x => bundler.itemIncludedInBuild(x))
        .map(dependency => bundler.configureDependency(dependency))
    )
    // Add dependencies in the same order as they were entered
    // to prevent a wrong module load order.
    .then(descriptions => 
      descriptions.forEach(description => 
        bundle.addDependency(description)))
    .then(() => bundle);
  }

This code waits for all promises to be done and then adds the descriptions in the order as they have been in the dependencies array.

I hope this clears things up a bit.

1reaction
geletocommented, Aug 26, 2016

A workaround for this is to use prepend For instance instead of adding jquery to the dependencies, use "prepend": ["node_modules/jquery/dist/jquery.js"]

Read more comments on GitHub >

github_iconTop Results From Across the Web

Webpack bundles my files in the wrong order ... - Stack Overflow
Tools tell me there are dependency issues. When I view the file through the tool and my IDE, it is bundled in the...
Read more >
Dependency Pre-Bundling - Vite
Dependency pre-bundling only applies in development mode, and uses esbuild to convert dependencies to ESM. In production builds, @rollup/plugin-commonjs is used ...
Read more >
Resolving Dependencies - Bndtools
The OSGi Framework has always used a resolver to wire a given set of bundles together, ensuring that only valid wires are made....
Read more >
Introduction to the Dependency Mechanism - Apache Maven
Dependency scope is used to limit the transitivity of a dependency and to determine when a dependency is included in a classpath. There...
Read more >
Upgrading your build from Gradle 5.x to 6.0
Updates to bundled Gradle dependencies ... dependency graphs, have a wrong result or a randomized dependency order when lots of excludes were present....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found