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

Script error. at 0: #543

Closed
adamwynne opened this issue May 10, 2013 · 23 comments
Closed

Script error. at 0: #543

adamwynne opened this issue May 10, 2013 · 23 comments

Comments

@adamwynne
Copy link

Whenever I use Karma on my CI server I get:

Chrome 26.0 (Linux) ERROR
Script error.
at :0

I've seen it before on my local dev (mac) box where it happens occasionally, but it happens every time on my CI (linux) box

Has anyone ever seen this, or does anyone have any ideas to try?

@vojtajina
Copy link
Contributor

It sounds like http://stackoverflow.com/questions/5913978/cryptic-script-error-reported-in-javascript-in-chrome-and-firefox

Don't think this is a Karma issue. If you think otherwise, please re-open this issue.

@edmondop
Copy link

edmondop commented Nov 1, 2013

How did you solve this @adamwynne ?

@adamwynne
Copy link
Author

I moved to PhantomJS and it worked

Sent from my iPhone

On 1 Nov 2013, at 08:12 am, Edmondo Porcu [email protected] wrote:

How did you solve this @adamwynne ?


Reply to this email directly or view it on GitHub.

@bettysteger
Copy link

I also moved to PhantomJS and I still get this error, has someone an idea why this happens?

my problem is similiar to this one: http://stackanswers.com/questions/24787444/phantomjs-and-karma-jasmine-tests-linux-error

@maksimr
Copy link
Contributor

maksimr commented Oct 22, 2014

@lpsBetty What version of karma and karma-phantomjs-launcher you use?

@bettysteger
Copy link

    "karma": "~0.12.24",
    "karma-phantomjs-launcher": "~0.1.4",

@maksimr
Copy link
Contributor

maksimr commented Oct 22, 2014

@lpsBetty problem on CI, only?

@bettysteger
Copy link

yes unfortunately..

@maksimr
Copy link
Contributor

maksimr commented Oct 22, 2014

@lpsBetty try run karma watch on CI and connect to it using browser on your machine for debugging.

@bettysteger
Copy link

I don't know how a can connect to the remote build..

but I now have tried different browsers on my SSH connected Debug build.. and Firefox works.. I really don't know why, but I got this:

PhantomJS 1.9.7 (Linux): Executed 102 of 102 ERROR (1.294 secs / 1.283 secs)
Firefox 28.0.0 (Linux): Executed 102 of 102 SUCCESS (1.609 secs / 1.468 secs)
Chrome 37.0.2062 (Linux): Executed 102 of 102 ERROR (1.634 secs / 1.615 secs)

@bettysteger
Copy link

ok now I know what's the problem.. there was an external JS file which caused that error. I used $.getScript to get a external library ... now I can finally fix this :)

do you know why it only says Script error.?

@maksimr
Copy link
Contributor

maksimr commented Oct 23, 2014

@lpsBetty awesome!)

do you know why it only says Script error.?

The "Script error." happens in Firefox, Safari, and Chrome when an exception violates the browser's same-origin policy

@bettysteger
Copy link

Thanks I already read that ;) Strange though, that it worked with Firefox.

@kylethornton
Copy link

@lpsBetty just wondering what you did to fix this. I have the same exact scenario and just trying to figure out a way around it.

@adamwynne
Copy link
Author

I just moved to PhantomJS and it went away

On Wed, Mar 11, 2015 at 6:27 PM, Kyle Thornton [email protected]
wrote:

@lpsBetty https://github.com/lpsBetty just wondering what you did to
fix this. I have the same exact scenario and just trying to figure out a
way around it.


Reply to this email directly or view it on GitHub
#543 (comment).

@bettysteger
Copy link

@kylethornton if you debug your tests in the browser you can see the error in the console..

my error was caused by an external JS which was expecting a specific ID on a form element.. so I added the HTML in the test..

@kylethornton
Copy link

Thanks @lpsBetty. My error messages in the browser weren't as helpful, but I ended up just mocking $.getScript to give me more control of what happened with the callback. Since these are unit tests I only care about how my code is functioning anyway.

@bettysteger
Copy link

ok, I am glad you found a solution!

@Deepakdubey90
Copy link

why phantomJs witrh karma throw error : ""Some of your tests did a full page reload!"" most of the time during UI Unit-Test-case . & how to fix it..?

@maxime1992
Copy link

I've had the exact same problem with angular cli.

Turns out it was a circular dependency (and I'm pretty glad that it was caught).

So if you've got that error when running ng test, just run instead ng serve which shows the circular dependencies as warnings, figure out which function, variable or whatever you've got to move and move it to break the circular dependency.

@ramuda
Copy link

ramuda commented Sep 28, 2018

probably you need ts-helpers

@trusktr
Copy link

trusktr commented Mar 3, 2020

I had this problem (the "Script error" message with no helpful information), and here's how I fixed it.

This might not work for you, and maybe there are more causes than what I fixed in my case, but the following might help debug.

In my case I am using karma-electron, but that may not matter much, as this error appears to happen with different browsers, as mentioned here and in #1268.

It appears that when there are uncaught errors, the browser propagates the error to Karma somehow, but without all the details.

So what I did (and it is ugly) was I made karma wrap all my tests with try-catch blocks, and in the catch(err) block I call console.log(err) and then re-throw the error so that the error continues to propagate as usual.

This completely solved the issue for me, now any errors are logged to console.

One way that you can set this up is, at the top of your karma.config.js file,

  • use a tool like globby to get a list of all your test files.
  • for each test file
    • read the content
    • prepend the line try { at the beginning of the file (but after import statements if you're using those)
    • append a } catch (e) { console.log(e); throw e } line to the end of the file
    • Note, basically this try-catch wraps your describe calls.
    • Note, if you're using require, wrap the require() calls too (unlike with imports, which can't be wrapped) to catch more errors.
    • write the files to a new location, like ./tmp-karma-test-build
  • Now update your config file's files field to point to the new files, so Karma will load the modified test files instead of the original ones.
  • In your script where you run the karma command, make sure to erase the .tmp-karma-test-build folder, and add it to your .gitignore

Basically that's what I did, more or less. Now when I run Karma, I see helpful error messages logged to console instead of just Script error. at :0:0.

Note, a more robust way to do it is make new entry points in the .tmp-karma-test-build folder, where each entry point uses require() or import() to import your actual test files from their original locations. Then, just wrapt the require() or import() calls with try-catch to catch all possible errors, even with ES Modules. This is easy to set up if your tests use require() but if your tests use ES Module import then you'll need to use @babel/register in the entry points (faster?) or karma-webpack in your Karma config (slower?).

Your mileage may vary if it isn't the same issue.

@trusktr
Copy link

trusktr commented Mar 3, 2020

This seems to be a Karma bug, considering that this happens in various browsers, not just one specifically, and this issue may actually need to be re-opened.

EDIT: #1268 is still open.

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

No branches or pull requests

10 participants