Skip to content

Control order of script loading #1031

@mrchops1024

Description

@mrchops1024
  1. OS? Windows 7, 8 or 10. Linux (which distribution). Mac OSX (Yosemite? El Capitan?)
    Windows 10
  2. Versions. Please run ng --version. If there's nothing outputted, please
    angular-cli: 1.0.0-beta.5
    node: 6.2.0
    os: win32 x64
  3. Repro steps. Was this an app that wasn't created using the CLI? What change did you
    do on your code? etc.

Trying something simple such as using bootstrap, which requires jquery. The only way I can get it to work properly is to explicitly load them in order via script tags in my index.html. Otherwise bootstrap seems to always finish loading first, throwing an error since jquery isn't loaded yet.

angular-cli-build.js

var Angular2App = require('angular-cli/lib/broccoli/angular2-app');

module.exports = function(defaults) {
  return new Angular2App(defaults, {
    vendorNpmFiles: [
      'systemjs/dist/system-polyfills.js',
      'systemjs/dist/system.src.js',
      'zone.js/dist/**/*.+(js|js.map)',
      'es6-shim/es6-shim.js',
      'reflect-metadata/**/*.+(js|js.map)',
      'rxjs/**/*.+(js|js.map)',
      '@angular/**/*.+(js|js.map)',
      'jquery/dist/jquery.js',
      'bootstrap/dist/**/*'
    ]
  });
};

system-config.ts (user config)

/***********************************************************************************************
 * User Configuration.
 **********************************************************************************************/
/** Map relative paths to URLs. */
const map: any = {
  'jquery': 'vendor/jquery',
  'bootstrap': 'vendor/bootstrap'

};

/** User packages configuration. */
const packages: any = {
  'jquery': {
    format: 'cjs',
    defaultExtension: 'js',
    main: 'dist/jquery.js'
  },
  'bootstrap': {
    format: 'cjs',
    defaultExtension: 'js',
    main: 'dist/js/bootstrap.js'
  }
};

admin.component.ts

import { Component, OnInit, OnDestroy } from '@angular/core';
import { AdduserComponent } from './adduser/';
import { Routes , ROUTER_DIRECTIVES, ROUTER_PROVIDERS} from '@angular/router';
import 'jquery';
import 'bootstrap';
...
  1. The log given by the failure. Normally this include a stack trace and some
    more information.

zone.js:461 Unhandled Promise rejection: Error: Bootstrap's JavaScript requires jQuery

When debugging in chrome and sorting 'Timeline - Start Time' I see this:
snag-0693

Sorting 'Tiimeline - End Time':
snag-0694

Am I missing something fundamental here? I'd like to avoid loading via script tags and utilize bundling, but I can't seem to figure out how to make this seemingly simple functionality work. I already ripped angular-material out of the project because of errors using -prod (looks like there are a few open issues for similar issues). Didn't expect bootstrap/jquery to also give me grief.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions