Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uncaught TypeError: Unexpected anonymous System.register call. #861

Closed
zeeshanjan82 opened this issue Oct 21, 2015 · 49 comments
Closed

Uncaught TypeError: Unexpected anonymous System.register call. #861

zeeshanjan82 opened this issue Oct 21, 2015 · 49 comments
Labels

Comments

@zeeshanjan82
Copy link

I am using Systemjs and angularjs and whenever I load my application which is also using jspm I get this error in the console.

@guybedford
Copy link
Member

@zeeshanjan82 can you share a test case here at all, or isolate the issue?

@zeeshanjan82
Copy link
Author

@guybedford It will take me some time to isolate the issue and provide some more details. I will revert back in couple of days.

@smcmurray
Copy link

I'm getting similar errors and having a hard time isolating them.

In my html, I have

<script type="text/javascript" src="/lib/system.js"></script>
<script type="text/javascript" src="/config.js"></script>
<script type="text/javascript">System.import('./app.js')</script>

And inside ./app.js I have

import a from 'a';
import b from 'b';
import c from 'c';

The error jumps erratically around, sometimes pointing at b, sometimes at c. I can't nail down a testcase.

@ghost
Copy link

ghost commented Oct 27, 2015

This is also happening for me, but only in Firefox. Chrome/Safari/IE11 seem to be unaffected. The issue seems to disappear on FF Dev Edition

@guybedford
Copy link
Member

@lyptt are you sure you are running the latest version of SystemJS?

@ghost
Copy link

ghost commented Oct 27, 2015

@guybedford I should be yes, I'm on SystemJS 0.19.5 according to my jspm_packages.

@guybedford
Copy link
Member

@lyptt sure, is there anyway you can share a reproducible case for this?

@ghost
Copy link

ghost commented Oct 27, 2015

@guybedford I'll definitely give it a go. The project I found the issue on is a bit complex so I'll have to come up with something a bit simpler

@guybedford
Copy link
Member

Thanks, would be appreciated.

@smcmurray
Copy link

I'm grasping at straws a bit here, but I have this problem in conjuction with issue #873. Trying to track down that issue, the browser points me to an anonymous function call in system.src.js:4573.

In the version I am running (0.19.5 Standard), line 4573 is:
bootstrap();

I'm confused at how I reach line 4573 because it is guarded by the if clause:
if (typeof Promise === 'undefined' || !hasURL)
In my browser (Chrome 45.0.2454.101 (64-bit)), Promise is a function and new URL('test:///').protocol == 'test:'

@jmathai
Copy link

jmathai commented Oct 27, 2015

@smcmurray which version of Firefox are you on? Using a version < 41.0.2 didn't come across this but we have two people that started to get this error once Firefox upgraded to 41.0.2. Not sure if that's a culprit but seems suspicious.

@smcmurray
Copy link

@jmathai, the report above is using Chrome 45.0.2454.101 (64-bit)

@smcmurray
Copy link

@jmathai, similar results in Firefox 41.0

@guybedford
Copy link
Member

If you're getting this issue, can you try adding this configuration to SystemJS:

System.config({ globalEvaluationScope: false })

And let me know if that helps?

@smcmurray
Copy link

@guybedford same results with globalEvaluationScope: false

@guybedford
Copy link
Member

I guess help replicating would be the way forward then.

@justinwoodcock
Copy link

I'm able to reproduce in firefox v41.0.2 by simply installing and enabling firebug, can anyone confirm? Will test the globalEvaluationScope fix and report back. @guybedford @jmathai @smcmurray

@guybedford
Copy link
Member

@justinwoodcock thanks, this is a Firebug issue, which I've posted in #878. There are of course many other reasons this message can appear, including user error though.

@olanod
Copy link

olanod commented Oct 30, 2015

I'm getting this error but is not related to firefox. I get it with the karma preprocessor and the jade plugin.

@monokrome
Copy link

Not sure if it helps, but I'm getting it in Chrome with this source.

@SerkanSipahi
Copy link

@guybedford getting the same error but with karma see repo: https://github.com/SerkanSipahi/app-decorators

System.config({ globalEvaluationScope: false }) has no effect !

git clone https://github.com/SerkanSipahi/app-decorators.git
cd app-decorators
npm install
node_modules/.bin/karma start

Firefox 41.0.0 (Mac OS X 10.11.0) ERROR
  TypeError: Unexpected anonymous System.register call.
  at app-decorators/node_modules/systemjs/dist/system.src.js:2692

Chrome 46.0.2490 (Mac OS X 10.11.0) ERROR
  Uncaught TypeError: Unexpected anonymous System.register call.
  at app-decorators/node_modules/systemjs/dist/system.src.js:2692

@frapontillo
Copy link

I am having the exact same issue as @SerkanSipahi but by running karma on PhantomJS.
The full output is:

PhantomJS 1.9.8 (Mac OS X 0.0.0) ERROR
  TypeError: Unexpected anonymous System.register call.
  at bower_components/system.js/dist/system.src.js:2692

The injected files in Karma are:

[ 'bower_components/system.js/dist/system-polyfills.src.js',
  'bower_components/system.js/dist/system.src.js',
  'bower_components/angular/angular.js',
  'bower_components/angular-mocks/angular-mocks.js',
  '.tmp/my-compiled-library.js',
  'src/**/*.html' ]

@SerkanSipahi
Copy link

@frapontillo i switched to https://github.com/Workiva/karma-jspm , this works fine for me. See my working state: https://github.com/SerkanSipahi/app-decorators ( master branch or tag test.karma.jspm )

git clone https://github.com/SerkanSipahi/app-decorators.git
npm install
node_modules/.bin/karma start

@jimschubert
Copy link

Another way this error can occur is if you pass your System.config registration through a transpiler with incompatible settings (e.g. babel with the modules='system' option).

This will result in something like:

System.register([], function (_export) {
  "use strict";

  return {
    setters: [],
    execute: function () {
      System.config({
      });
    }
  };
});

Which will get you the error. Don't run config.js or whatever through your transpiler and if this is one of the scenarios resulting in the error, it should start working.

@tbragaf
Copy link

tbragaf commented Nov 30, 2015

Is it possible you are using a config.js?

Can you remove config.js and place it inside a script in index.html?
Also, can you try to export config.js as a module?

My config.js looked like this:

System.register([], function($__export) {
  "use strict";
  return {
    setters: [],
    execute: function() {
      System.config({map: {'traceur-runtime': '../node_modules/gulp-traceur/node_modules/traceur/bin/traceur-runtime.js'}});
      System.import('bootstrap.js').catch(function(response) {
        console.error(response);
      });
    }
  };
});

So, the error is true, the module has no name, it is an anonymous module.
Does this help?

Best regards,
tbragaf

@monokrome
Copy link

My repo (linked above) has the same issue that @tbragaf has just posted. There is no config.js on my machine. Is the comment in #861 (comment) possible explanation of this issue?

@jimschubert
Copy link

@monokrome I don't see systemjs in your repo. Did you link to the right thing?

@tbragaf
Copy link

tbragaf commented Dec 3, 2015

@monokrome
As @jimschubert mentioned, you shouldn't transpile the config.js
Please provide your repo so we can take a look :)

@monokrome
Copy link

@tbragaf I linked the repo above, it's here. I don't know if it's helpful or not, but it was the same error that I was having. What I was saying is that there isn't a config.js in there, though.

@jithine
Copy link

jithine commented Dec 3, 2015

I am seeing this error on Firefox, not on Chrome though. And restarting FF makes this go away for a while.

@tbragaf
Copy link

tbragaf commented Dec 4, 2015

@monokrome Oh I see, you are using concat to add systemjs. Sorry, but I couldn't run the branch.
You shouldn't transpile the systemjs right?
I am not sure, but you are adding systemjs to src and then transpiling? Is that correct? I am not a big gulp user, sorry.

@justin-schroeder
Copy link
Contributor

I'm also seeing this error on Firefox (40.0.3) and firefox only. I've tried numerous configurations, two things that stood out in all this:

  • Exception is thrown on any ES6 import statements, when using babel for realtime transpiling. No exceptions are thrown when compiling ahead of time and only loading ES5.
  • I had a reference to an undefined variable in my code (oddly, in a scope which wasn't even being executed), thus I assumed it was completely unrelated, but when I corrected it, the all TypeError: Unexpected anonymous System.register call. exceptions went away.

Could this be babel choking on minor js bugs that arise when transpiling in SpiderMonkey but not V8?

@guybedford
Copy link
Member

@justin-schroeder is this with Firebug running or not?

@mnichols
Copy link

I am running FF 42.0 on OSX and can confirm that adding globalEvaluationScope: false to my config.js made the error go away. I am not running Firebug.

@guybedford
Copy link
Member

@mnichols thanks for the update... I'm hoping to make that the default in future.

@unional
Copy link
Contributor

unional commented Jan 29, 2016

Seems like I still encounter this issue, with globalEvaluationScope: false.
When Firebug is not running, It have this warning instead: unreachable code after return statement when I open Firebug to check.

Here is the repo:
https://github.com/coolcodeexamples/timely-wealth-game

@guybedford
Copy link
Member

@unional try disabling Firebug entirely?

@unional
Copy link
Contributor

unional commented Feb 1, 2016

I re-test it and somehow it is working now. With and without firebug.

And I noticed I actually don't have firebug installed in that environment. Just the basic dev-tool.
I have verified it is working on all counts: w/wo dev-tool opened (i.e. firebug not present or disabled), w/wo firebug opened.

For reference:

  • jspm 0.16.25
  • ts 2.5.5
  • firefox 44.0 (windows, osx), 42.0 (osx)

@pheara
Copy link

pheara commented Feb 8, 2016

I'm experiencing similiarly sounding problems on firefox 43.0 (windows) with jspm 0.16.27.

When i change the order of the includes in the app.js, different files trigger the error. However I haven't managed to track down the specific import at fault yet. (It's not the first import though, which suggests that it's a specific import, doesn't it?)

EDIT: Just opened a new tab without changing anything afair and it works. On the first reload in that tab, the same error occured again. Some weird caching behaviour maybe?

@monokrome
Copy link

@tbragaf Not sure if this is still helpful, but - as a response to your previous question - the tsFilter pipe in my repository only lets TypeScript files through, so SystemJS won't be transpiled in my example. It'll be concatenated into the beginning of the file, and then the ts files will be afterward. The tsFilter.restore is the part that brings the non-TypeScript files back into the stream.

Not sure how much more helpful I can be at this point. I've pretty much given up on SystemJS at this point and have moved to webpack.

@djindjic
Copy link

djindjic commented Mar 7, 2016

also have same issue by running karma jasmin tests in typesctipt "visual studio" project without jspm

@djindjic
Copy link

djindjic commented Mar 7, 2016

I've fixed it by using System.import instead of es6 import statement for unit test dependencies.

@luixo
Copy link

luixo commented Mar 9, 2016

Opening debugger triggers cache-related problem: loading fails on libs with AMD support (react, underscore) with error: AMD module file:///C:/path_to_libs/underscore.js did not define
Setup:

  • Firefox 41.0.2
  • SystemJS v0.19.23
  • Modules are transpiled from import/export syntax by babel plugin

@pheara
Copy link

pheara commented Mar 9, 2016

It might be related to the dynamic compiling. When I run the exact same setup as mentioned above but loading a bundled app instead, the error is gone.

@luixo
Copy link

luixo commented Mar 9, 2016

Seems like adding map for library in config somehow solves the problem.
UPD: Nope, opening debugger still crash loader.
UPD2: Breaking on a point inside of SystemJSLoader.prototype.register function magically heals the problem. And it is definitely about AMD modules.

@luixo
Copy link

luixo commented Mar 10, 2016

Temporarily fixed this problem, but very strange way. I have a plugin that override fetch method for loading and try to grab file from several paths (prepared path is formed in overriden locate method). When i add some guranteed failed path for load, fetching takes more time than usual and in 9 from 10 cases i can use debugger safely. Example plugin code:

Promise.reduce = (fns, val) => fns.reduce((prev, current) => prev.then(result => current(result)), val instanceof Promise ? val : Promise.resolve(val));
exports.locate = load => {
    try {
        let customPath = load.name;
        return `file:///C:/fail.txt|${customPath }`;
    }
    catch (e) { return load.name; }
};
exports.fetch = (load, loader) => {
    let paths = load.address.split('|');
    return Promise.reduce(paths.map((_, index) =>
            () => Promise.resolve(load.address = paths[index])
                .then(() => loader(load))
                .then(loadedFile => Promise.reject(loadedFile), failed => Promise.resolve(failed))
    ))
        .then(err => Promise.reject(`Failed to load files on: ${paths.join('; ')}, sample error: ${err}`), loadedFile => Promise.resolve(loadedFile))
};

Hope developers that know systemjs code better than me could reproduce and locate the problem.

@alexkmbk
Copy link

I'm getting this error in very simple example and asked a question in stackoverflow:
http://stackoverflow.com/questions/36176523/javascript-error-unexpected-anonymous-system-register-call

No answer :-(

@geea-develop
Copy link

geea-develop commented May 15, 2016

for me its actually because the load sent to
hook('reduceRegister_', function() {
is null.

this is the full stack trace
Error: Unexpected anonymous System.register call.
Evaluating http://localhost:9000/dist/auth-config.js
Error loading http://localhost:9000/dist/auth-config.js as "auth-config" from http://localhost:9000/dist/main.js
Stack trace:
"bootstrap/</</</<@http://localhost:9000/jspm_packages/system.src.js:2681:1bootstrap/</</<@http://localhost:9000/jspm_packages/system.src.js:3221:1bootstrap/</</</</<@http://localhost:9000/jspm_packages/system.src.js:3750:1bootstrap/</</</<@http://localhost:9000/jspm_packages/system.src.js:2411:9bootstrap/</</SystemJSLoader.prototype.register@http://localhost:9000/jspm_packages/system.src.js:2636:1anonymous/<@http://localhost:9000/dist/auth-config.js:1:20anonymous@http://localhost:9000/dist/auth-config.js:1:1evalExec@http://localhost:9000/jspm_packages/system.src.js:1338:7bootstrap/</</__exec@http://localhost:9000/jspm_packages/system.src.js:1355:1bootstrap/</</</<@http://localhost:9000/jspm_packages/system.src.js:3054:11bootstrap/</</<@http://localhost:9000/jspm_packages/system.src.js:3306:12bootstrap/</</</<@http://localhost:9000/jspm_packages/system.src.js:3567:14bootstrap/</</</<@http://localhost:9000/jspm_packages/system.src.js:3872:14bootstrap/</</</<@http://localhost:9000/jspm_packages/system.src.js:4086:16proceedToTranslate/</<@http://localhost:9000/jspm_packages/system.src.js:346:16"

in the pushRegister hook it goes to the last else
this.reduceRegister
(null, register);

@phicho
Copy link

phicho commented Dec 7, 2017

The error was happening for me because i was loading the js files from a script tag and also through systemjs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests