0

I started getting this error today in the test suite of an Angular.js 1.5/Angular 5 project:

HeadlessChrome 64.0.3282 (Linux 0.0.0) ERROR
  An error was thrown in afterAll
  Uncaught ReferenceError: require is not defined

The issue appears after all of my tests have run successfully. What is bizarre is it runs well locally, but it's in a Jenkins CI server where it fails. From the other developers only 1 in 10 is seeing the same problem as Jenkins.

There are tons of other posts mentioning this same error but none addressed my exact problem, like this, this, this, ...

Anybody knows what the issue can be?

Edit:

The exception happens in modernizr/lib/cli.js, but no stack-trace appears:

enter image description here

and we get no call stack either:

enter image description here

Daniel
  • 21,933
  • 14
  • 72
  • 101

1 Answers1

0

After looking at the bower dependencies of our project with bower ls -o, we found a difference in a transient dependency of Zurb Foundation.

In the places were it worked, modernizr was set to 3.5.0:

├─┬ foundation#5.5.1
│ ├── fastclick#1.0.6
│ ├── jquery#2.1.4
│ ├─┬ jquery-placeholder#2.0.9
│ │ └── jquery#2.1.4
│ ├─┬ jquery.cookie#1.4.1
│ │ └── jquery#2.1.4
│ └── modernizr#3.5.0

In the places were it didn't work, it was set to 3.9.0:

├─┬ foundation#5.5.1
│ ├── fastclick#1.0.6
│ ├── jquery#2.1.4
│ ├─┬ jquery-placeholder#2.0.9
│ │ └── jquery#2.1.4
│ ├─┬ jquery.cookie#1.4.1
│ │ └── jquery#2.1.4
│ └── modernizr#3.9.0

Forcing the modernizr version to 3.5.0 in bower.json solved the issue:

  "dependencies": {
    ...
    "modernizr": "3.5.0"
  }

I don't fully understand why modernizr was resolved to different versions in some computers, as in both cases we had the same Zurb Foundation's version pinned, but this was the way we fixed the issue.

Daniel
  • 21,933
  • 14
  • 72
  • 101
  • It is because of the SemVer selector >=2... so it will use the latest release. This is normal and expected. You should file an issue for the modernizr project. See https://github.com/foundation/foundation-sites/blob/v5.5.1/bower.json#L13 –  Feb 17 '20 at 06:20
  • To be exact, require is only available in Node environments. So far I can not see the cause in the modernizr releases. Can you share the full stacktrace with us? –  Feb 17 '20 at 06:46
  • @DanielRuf There is no stack trace printed out, the 3 lines I posted are all the error information we get. We found out it was modernizr because of that 1 developer for whom the issue reproduced locally, so he could debug the test execution. I'll ask him for an screenshot of the call stack when he gets the error and I'll update tomorrow. – Daniel Feb 18 '20 at 04:36
  • Can you share a repo with the code that triggers / causes this? –  Feb 18 '20 at 05:25
  • That would be great. Because I think it was caused by something else. –  Feb 18 '20 at 05:25
  • @DanielRuf added a image of the error we see in Chrome when running the tests without the headless option. – Daniel Feb 18 '20 at 21:03
  • Well, it was like this for a very long time. So this file alone can not be the cause. See https://unpkg.com/browse/modernizr@3.1.0/lib/cli.js –  Feb 18 '20 at 21:13