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

Angular 8 universal not working gives an error strict mode code may not contain 'with' statements #170

Open
Garudkar-Dnyaneshwar opened this issue Oct 22, 2020 · 4 comments

Comments

@Garudkar-Dnyaneshwar
Copy link

This error comes to me via usage of Angular Universal. When attempting to serve my development server and accessing any of the pages, I am greeted to a blank screen and this error in the console:

SyntaxError: strict mode code may not contain 'with' statements

specifically pointing to this line as the issue: './node_modules/domino/lib/sloppy.js'

module.exports = { Window_run: function _run(code, file) { if (file) code += '\n//@ sourceURL=' + file; with(this) eval(code); ==>>>showing error }, EventHandlerBuilder_build: function build() { try { with(this.document.defaultView || Object.create(null)) with(this.document) with(this.form) with(this.element) return eval("(function(event){" + this.body + "})"); } catch (err) { return function() { throw err; }; } } };

@khaled-elrifaay
Copy link

any updates , i faced this issue

@Garudkar-Dnyaneshwar
Copy link
Author

any updates , i faced this issue

Nope, I tried everything but cant find any solution. So finally I migrate my whole project into nextjs

@khaled-elrifaay
Copy link

solution

ummm okay thanks

@jb-modist
Copy link

Depending on your use case you can use patch-package to remove the non-compliant code. I'm using domino as a dependancy of turndown and as far as I can tell sloppy.js isn't needed in my case.

I created the patch file:

diff --git a/node_modules/domino/lib/sloppy.js b/node_modules/domino/lib/sloppy.js

index b5d8950..e920db1 100644
--- a/node_modules/domino/lib/sloppy.js
+++ b/node_modules/domino/lib/sloppy.js
@@ -6,19 +6,9 @@
 /* jshint -W085 */
 module.exports = {
   Window_run: function _run(code, file) {
-    if (file) code += '\n//@ sourceURL=' + file;
-    with(this) eval(code);
+    console.log("Window_run removed")
   },
   EventHandlerBuilder_build: function build() {
-    try {
-      with(this.document.defaultView || Object.create(null))
-        with(this.document)
-          with(this.form)
-            with(this.element)
-              return eval("(function(event){" + this.body + "})");
-    }
-    catch (err) {
-      return function() { throw err; };
-    }
+    console.log("EventHandlerBuilder_build removed")
   }
 };

which I deploy to the server by adding
"postinstall": "patch-package"

as a package.json script.

This solved the problem for me.

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

3 participants