0

currently, I work for a school project and want to show some charts with angularJs and meteor.

I want to use the ui-router plugin. But when I try to use it, I get the following error:

Error: only one instance of babel/polyfill is allowed
at Object.eval (eval at <anonymous> (http://localhost:3000/packages/jquery.js?hash=22a0055f59bd150c435c5aba34c7c59076b8bcd9:397:22), <anonymous>:2872:9)
at Object.1.180 (eval at <anonymous> (http://localhost:3000/packages/jquery.js?hash=22a0055f59bd150c435c5aba34c7c59076b8bcd9:397:22), <anonymous>:2875:4)
at s (eval at <anonymous> (http://localhost:3000/packages/jquery.js?hash=22a0055f59bd150c435c5aba34c7c59076b8bcd9:397:22), <anonymous>:2863:254)
at e (eval at <anonymous> (http://localhost:3000/packages/jquery.js?hash=22a0055f59bd150c435c5aba34c7c59076b8bcd9:397:22), <anonymous>:2863:425)
at eval (eval at <anonymous> (http://localhost:3000/packages/jquery.js?hash=22a0055f59bd150c435c5aba34c7c59076b8bcd9:397:22), <anonymous>:2863:443)
at eval (eval at <anonymous> (http://localhost:3000/packages/jquery.js?hash=22a0055f59bd150c435c5aba34c7c59076b8bcd9:397:22), <anonymous>:7043:4)
at eval (eval at <anonymous> (http://localhost:3000/packages/jquery.js?hash=22a0055f59bd150c435c5aba34c7c59076b8bcd9:397:22), <anonymous>:7050:3)
at eval (<anonymous>)
at http://localhost:3000/packages/jquery.js?hash=22a0055f59bd150c435c5aba34c7c59076b8bcd9:397:22
at Function.globalEval (http://localhost:3000/packages/jquery.js?hash=22a0055f59bd150c435c5aba34c7c59076b8bcd9:398:7) <div ui-view="" class="ng-scope" data-ng-animate="1">

Also I get this warning:

Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user's experience. For more help, check https://xhr.spec.whatwg.org/.

I have really no idea what this message want to tell me. I didnt load babel/polyfill more than one time. Before I got this message I even didnt know of this plugin.

This is my main.js with the ui-router code:

import angular from 'angular';
import angularMeteor from 'angular-meteor';
import uiRouter from 'angular-ui-router';
import ngMaterial from 'angular-material';
import '../../../node_modules/angular-material/angular-material.css'
import '../own.css';
import template from './main.html';
import { name as Navigation } from '../navigation/navigation';
import {name as Toolbar} from '../toolbar/toolbar';
import {name as View1} from '../view1/view1';
import {name as View2} from '../view2/view2';

class Main {}

const name = 'main';

// create a module
export default angular.module(name, [
angularMeteor,
uiRouter,
Navigation,
Toolbar,
View2,
View1,
ngMaterial
]).component(name, {
template,
controllerAs: name,
controller: Main
})
.config(config);
function config($mdThemingProvider,$urlRouterProvider,$stateProvider ) {
'ngInject';


$urlRouterProvider.otherwise('view1');

$stateProvider
    .state('view1', {
        url: '/',
        templateUrl: 'test.html'
    });

$mdThemingProvider
    .theme('default')
    .primaryPalette('orange')
    .accentPalette('deep-orange')
    .warnPalette('red');
}

And this is the code of my main.html where the view should be injected:

<div layout="column" style="height: 100%">
<toolbar scroll></toolbar>
<section layout="row" flex>

    <navigation></navigation>

    <md-content flex layout-padding style="margin-top: 75px">
<div ui-view=""></div>
    </md-content>
</section>

Without ui-router it works fine!

What is the problem here?

tiga05
  • 3
  • 1
  • 7

3 Answers3

0

Most likely you have a module that is requiring babel-polyfill to compile and it's polluting your global namespace with multiple versions of babel. Therefore you want to either tell babel to ignore node_modules directory and or figure out which dependency is requiring babel-polyfill and prevent that.

The final option is to compile the code with the runtime transformer.

https://babeljs.io/docs/plugins/transform-runtime/

Chris Hawkes
  • 11,923
  • 6
  • 58
  • 68
  • Thank you for your answer. Can you give me an example how to ignore the node_modules folder? As I already wrote: I think the ui-router is the problem. It doesnt work with enabled ui-router. – tiga05 Nov 09 '16 at 08:07
0

I found the solution.

Something was wrong with the $stateprovider.

I copied this code

$stateProvider
.state('view1', {
    url: '/',
    templateUrl: 'test.html'
});

into the view and changed it to this:

function config($stateProvider) {
'ngInject';
$stateProvider
    .state('view1', {
        url: '/view1',
        template: '<view1></view1>'
    });

}

(Last code example is already the finished code from my project). So no more templateUrl, but template now.

I have REALLY no idea why this works, but it works. Maybe there is someone who can explain this?

tiga05
  • 3
  • 1
  • 7
0

Try to delete your local file

build/
dist/

However, it works for me.

Allan
  • 27
  • 5