domino
domino copied to clipboard
Angular 8 universal not working gives an error strict mode code may not contain 'with' statements
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; }; } } };
any updates , i faced this issue
any updates , i faced this issue
Nope, I tried everything but cant find any solution. So finally I migrate my whole project into nextjs
solution
ummm okay thanks
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.