简体   繁体   中英

ES6 — importing of es5 files

I try to use this ( https://github.com/gocardless/es6-angularjs/blob/master/README.md ) as a starting point and then include the bootstrap javascript code. In order to open a modal

But the only thing that happens is:

Potentially unhandled rejection [3] Error loading "components/bootstrap/dist/js" at http://localhost:3010/components/bootstrap/dist/js.js
Error loading "components/bootstrap/dist/js" from "app-compiled/bootstrap" at http://localhost:3010/app-compiled/bootstrap.js
Not Found: http://localhost:3010/components/bootstrap/dist/js.js (WARNING: non-Error used)

I added this to the main.js:

import 'bootstrap-js';
//TODO please explain to me why not working

and this to the loader.config.js file:

System.config({
  meta: {

    ...,
    'components/bootstrap/dist/js':{ format: 'global', export: 'bootstrap'}


  },
  map: {

    ....,
    'bootstrap-js': 'components/bootstrap/dist/js'

  }
});
  1. Try exports instead of export here:
System.config({
    meta: {
    //...
        'components/bootstrap/dist/js':{ format: 'global', exports: 'bootstrap'}
    }
    //...
});
  1. When your write { format: 'global', exports: 'bootstrap'} you're trying to get global bootstrap variable. But such does not exists. So I think you must remove meta line and fix map. Result must be look like:
System.config({
    meta: {
        //...
        'components/path/to/jquery': { format: 'global', exports: 'jQuery' },
        'components/bootstrap/dist/js/bootstrap': { deps: ['jquery'] }
    }
    map: {
        //...
        'jquery': 'components/path/to/jquery',
        'bootstrap-js': 'components/bootstrap/dist/js/bootstrap'
    }
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM