turndown icon indicating copy to clipboard operation
turndown copied to clipboard

With statements cannot be used with the "esm" output format due to strict mode

Open cheetahbyte opened this issue 3 years ago โ€ข 33 comments

> node_modules/domino/lib/sloppy.js:10:4: error: With statements cannot be used with the "esm" output format due to strict mode
    10 โ”‚     with(this) eval(code);
       โ•ต     ~~~~

 > node_modules/domino/lib/sloppy.js:14:6: error: With statements cannot be used with the "esm" output format due to strict mode
    14 โ”‚       with(this.document.defaultView || Object.create(null))
       โ•ต       ~~~~

 > node_modules/domino/lib/sloppy.js:15:8: error: With statements cannot be used with the "esm" output format due to strict mode
    15 โ”‚         with(this.document)
       โ•ต         ~~~~

 > node_modules/domino/lib/sloppy.js:16:10: error: With statements cannot be used with the "esm" output format due to strict mode
    16 โ”‚           with(this.form)
       โ•ต           ~~~~

 > node_modules/domino/lib/sloppy.js:17:12: error: With statements cannot be used with the "esm" output format due to strict mode
    17 โ”‚             with(this.element)
       โ•ต             ~~~~

error when starting dev server:
Error: Build failed with 5 errors:
node_modules/domino/lib/sloppy.js:10:4: error: With statements cannot be used with the "esm" output format due to strict mode
node_modules/domino/lib/sloppy.js:14:6: error: With statements cannot be used with the "esm" output format due to strict mode
node_modules/domino/lib/sloppy.js:15:8: error: With statements cannot be used with the "esm" output format due to strict mode
node_modules/domino/lib/sloppy.js:16:10: error: With statements cannot be used with the "esm" output format due to strict mode
node_modules/domino/lib/sloppy.js:17:12: error: With statements cannot be used with the "esm" output format due to strict mode
    at failureErrorWithLog (C:\Users\user\AppData\Roaming\npm\node_modules\vite\node_modules\esbuild\lib\main.js:1224:15)
    at buildResponseToResult (C:\Users\user\AppData\Roaming\npm\node_modules\vite\node_modules\esbuild\lib\main.js:936:32)
    at C:\Users\Leonhard Breuer\AppData\Roaming\npm\node_modules\vite\node_modules\esbuild\lib\main.js:1035:20
    at C:\Users\Leonhard Breuer\AppData\Roaming\npm\node_modules\vite\node_modules\esbuild\lib\main.js:568:9
    at handleIncomingPacket (C:\Users\user\AppData\Roaming\npm\node_modules\vite\node_modules\esbuild\lib\main.js:657:9)
    at Socket.readFromStdout (C:\Users\user\AppData\Roaming\npm\node_modules\vite\node_modules\esbuild\lib\main.js:535:7)
    at Socket.emit (events.js:315:20)
    at addChunk (internal/streams/readable.js:309:12)
    at readableAddChunk (internal/streams/readable.js:284:9)
    at Socket.Readable.push (internal/streams/readable.js:223:10)
    ```
    I get this error, how can I fix it?

cheetahbyte avatar May 24 '21 19:05 cheetahbyte

Having the same problem

logycware avatar Jun 05 '21 09:06 logycware

Having the same problem

damianmozniak avatar Jun 14 '21 10:06 damianmozniak

There are some packaging changes in the master, so I'd like to ask you to try it first, i.e.:

  "dependencies": {
    "turndown": "github:domchristie/turndown"
  }

If the issue is still present, please provide a minimum buildable example reproducing the issue. Including:

  • package.json (or other build config file)
  • your Node.js version
  • a minimum script
  • instructions if applicable

Thank you!

martincizek avatar Jun 14 '21 11:06 martincizek

Hi @martincizek

The entry points for "turndown": "github:domchristie/turndown" are wrong.

There is no lib folder like referenced here in package.json from master:

"main": "lib/turndown.cjs.js",
"module": "lib/turndown.es.js",
"jsnext:main": "lib/turndown.es.js",

callmeberzerker avatar Jun 16 '21 09:06 callmeberzerker

@martincizek solution works for me

damianmozniak avatar Jun 16 '21 09:06 damianmozniak

@damianmozniak not sure how since there is no lib folder?

callmeberzerker avatar Jun 16 '21 10:06 callmeberzerker

@callmeberzerker lib exist after npm install so it's configured somewhere

damianmozniak avatar Jun 16 '21 10:06 damianmozniak

So it seems it was PR #335 what fixes this (merged but not released to npmjs).

We're currently in a process of transferring Turndown under a new organisation and I hope I'll be able to release a new npm package soon.

martincizek avatar Jun 16 '21 10:06 martincizek

~~To anyone to whom this is a blocker and is using yarn as their package manager - I have published the latest master and the dist and lib folders on my forked version.~~

~~You would need to add the following to your dependencies:~~

~~"turndown": "https://github.com/callmeberzerker/turndown/commit/ede17b4aee0ee12c1615d65b28f64b9aa3e2b7e8"~~

~~Hopefully the proper version is released as soon as possible.~~

The maintainer published a temp branch see here: https://github.com/domchristie/turndown/issues/378#issuecomment-862390985

callmeberzerker avatar Jun 16 '21 12:06 callmeberzerker

To anyone to whom this is a blocker and is using yarn as their package manager - I have published the latest master and the dist and lib folders on my forked version.

@callmeberzerker Not sure how this differ from the current master. I see three commits in your fork:

  1. You've commited generated stuff, which is not necessary, because dependencies are built automatically when linked as a git dependency.
  2. You've introduced a mistake in package.json
  3. You've fixed your mistake from previous commit :-), which leads to the same package.json as in Turndown's master (except the script externalisation, which should be irrelevant for the functionality).

Are you sure that the result is any different from using just:

  "dependencies": {
    "turndown": "github:domchristie/turndown"
  }

?

P.S. Don't forget to npm install in your project, that's what also builds the turndown dependency.

martincizek avatar Jun 16 '21 12:06 martincizek

Hi @martincizek

As I explained in previous comment, I am not using npm - but yarn (version 1) -> I basically need the published lib files irrelevant of my build/package manager. That's why I can't rely on "turndown": "github:domchristie/turndown" to be then run with npm to get the generated files.

callmeberzerker avatar Jun 16 '21 13:06 callmeberzerker

As I explained in previous comment, I am not using npm - but yarn (version 1) -> I basically need the published lib files irrelevant of my build/package manager.

I see. Not very familiar with yarn, I guess it's because of https://github.com/yarnpkg/yarn/issues/5235, right?

I've created a temporary branch with pre-built artifacts as a workaround until a new npm package is published. Would you mind to test it?

Workaround for yarn version 1:

  "dependencies": {
    "turndown": "github:domchristie/turndown#build-7.1"
  }

martincizek avatar Jun 16 '21 13:06 martincizek

First of all, thanks a lot for your prompt feedback and communication!

I can definitely confirm that it works with your branch -> I will edit my above comment to point your comment.

I know the whole node/js ecosystem is hurting big now with the esm/module/main semi-standardization going on now which is hell for lib authors and users - but we will get through it somehow!

Once again thanks a lot!

callmeberzerker avatar Jun 16 '21 14:06 callmeberzerker

Since my bug is fixed, and everyone else seems to be happy too, I'll close the issue :D

cheetahbyte avatar Jun 28 '21 16:06 cheetahbyte

@callmeberzerker @cheetahbyte Release 7.1 has been created and published to npm registry. Would you mind to test it, especially with yarn?

It should now be just:

  "dependencies": {
    "turndown": "^7.1.0"
  }

martincizek avatar Jun 28 '21 17:06 martincizek

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.

jb-modist avatar Nov 05 '21 17:11 jb-modist

same error Version: 7.1.1

Weyker avatar Jan 25 '22 22:01 Weyker

In html-parser.js

var domino = require('domino')
Parser.prototype.parseFromString = function (string) {
    return domino.createDocument(string)
}

to

import('domain').then(domino=>{
Parser.prototype.parseFromString = function (string) {
      return domino.createDocument(string)
    }
})

WenyaoL avatar Apr 08 '23 17:04 WenyaoL

Hi, I encountered the same error when I tried to migrate my nextjs app to use their new app router system. The problem appears when turndown is imported anywhere from the app directory. I created this repository to easily reproduce the error: https://github.com/julienc91/turndown-strict-mode

julienc91 avatar Sep 17 '23 17:09 julienc91

Hi, I upgraded a bunch of dependencies in my Nuxt project and this bug broke the Netlify build with this message require() of ES Module /var/task/.netlify/functions-internal/server nuxt/server.mjs not supported.

I was using turndown 7.1.2

Removing turndown from my project fixed the deployment

Karalix avatar Sep 20 '23 13:09 Karalix

ร— With statement are not allowed in strict mode โ•ญโ”€[/Users/danny/Documents/Target/Projects/node_modules/domino/lib/sloppy.js:13:1] 13 โ”‚ try { 14 โ”‚ with(this.document.defaultView || Object.create(null)) 15 โ”‚ with(this.document) 16 โ”‚ with(this.form) ยท โ”€โ”€โ”€โ”€ 17 โ”‚ with(this.element) 18 โ”‚ return eval("(function(event){" + this.body + "})"); 19 โ”‚ } โ•ฐโ”€โ”€โ”€โ”€

Does anyone find the solution for this ?? 

nextjs app : 13.5.4
turndown :

tried turndown :7.1.2 turndown :7.1.1 "turndown": "github:domchristie/turndown" "turndown": "github:domchristie/turndown#build-7.1"

    but still issue present
    

Growmedigitally avatar Oct 15 '23 16:10 Growmedigitally

Hi, I encountered the same error when I tried to migrate my nextjs app to use their new app router system. The problem appears when turndown is imported anywhere from the app directory. I created this repository to easily reproduce the error: https://github.com/julienc91/turndown-strict-mode

have you found any solution?

Growmedigitally avatar Oct 15 '23 16:10 Growmedigitally

> node_modules/domino/lib/sloppy.js:10:4: error: With statements cannot be used with the "esm" output format due to strict mode
    10 โ”‚     with(this) eval(code);
       โ•ต     ~~~~

 > node_modules/domino/lib/sloppy.js:14:6: error: With statements cannot be used with the "esm" output format due to strict mode
    14 โ”‚       with(this.document.defaultView || Object.create(null))
       โ•ต       ~~~~

 > node_modules/domino/lib/sloppy.js:15:8: error: With statements cannot be used with the "esm" output format due to strict mode
    15 โ”‚         with(this.document)
       โ•ต         ~~~~

 > node_modules/domino/lib/sloppy.js:16:10: error: With statements cannot be used with the "esm" output format due to strict mode
    16 โ”‚           with(this.form)
       โ•ต           ~~~~

 > node_modules/domino/lib/sloppy.js:17:12: error: With statements cannot be used with the "esm" output format due to strict mode
    17 โ”‚             with(this.element)
       โ•ต             ~~~~

error when starting dev server:
Error: Build failed with 5 errors:
node_modules/domino/lib/sloppy.js:10:4: error: With statements cannot be used with the "esm" output format due to strict mode
node_modules/domino/lib/sloppy.js:14:6: error: With statements cannot be used with the "esm" output format due to strict mode
node_modules/domino/lib/sloppy.js:15:8: error: With statements cannot be used with the "esm" output format due to strict mode
node_modules/domino/lib/sloppy.js:16:10: error: With statements cannot be used with the "esm" output format due to strict mode
node_modules/domino/lib/sloppy.js:17:12: error: With statements cannot be used with the "esm" output format due to strict mode
    at failureErrorWithLog (C:\Users\user\AppData\Roaming\npm\node_modules\vite\node_modules\esbuild\lib\main.js:1224:15)
    at buildResponseToResult (C:\Users\user\AppData\Roaming\npm\node_modules\vite\node_modules\esbuild\lib\main.js:936:32)
    at C:\Users\Leonhard Breuer\AppData\Roaming\npm\node_modules\vite\node_modules\esbuild\lib\main.js:1035:20
    at C:\Users\Leonhard Breuer\AppData\Roaming\npm\node_modules\vite\node_modules\esbuild\lib\main.js:568:9
    at handleIncomingPacket (C:\Users\user\AppData\Roaming\npm\node_modules\vite\node_modules\esbuild\lib\main.js:657:9)
    at Socket.readFromStdout (C:\Users\user\AppData\Roaming\npm\node_modules\vite\node_modules\esbuild\lib\main.js:535:7)
    at Socket.emit (events.js:315:20)
    at addChunk (internal/streams/readable.js:309:12)
    at readableAddChunk (internal/streams/readable.js:284:9)
    at Socket.Readable.push (internal/streams/readable.js:223:10)
    ```
    I get this error, how can I fix it?

have you find any solution?

Growmedigitally avatar Oct 15 '23 16:10 Growmedigitally

@Growmedigitally Not really fixed, but I managed to work around the problem by using JSDOM to bypass domino.

You can have a look at this commit here: https://github.com/julienc91/caviardeul/commit/75570c15a0db15e5c523a3b6b86773f04c594cf2

julienc91 avatar Oct 15 '23 17:10 julienc91

@Growmedigitally Not really fixed, but I managed to work around the problem by using JSDOM to bypass domino.

You can have a look at this commit here: julienc91/caviardeul@75570c1

Still not working same issue { "dependencies": {

.... "jsdom": "^22.1.0", "turndown": "^7.1.2" }, "devDependencies": { "@types/jsdom": "^21.1.3", "@types/turndown": "^5.0.2", } }

Growmedigitally avatar Oct 16 '23 03:10 Growmedigitally

also have the same issue when working with nextjs. Would it be possible to replace domino with JSDOM similar to what @julienc91 did in this repo?

I can't do it since I'm not depending directly on turndown but postlight/parser -> turndown -> domino :(

ioRekz avatar Oct 24 '23 16:10 ioRekz

Next14 issue related to this here - https://github.com/vercel/next.js/issues/34796

headline-design avatar Nov 16 '23 03:11 headline-design

Sandbox to reproduce the error when using Next JS 14.0.2 or 14.0.3 (for 14.0.1 or older it seems to build successfully): https://codesandbox.io/p/devbox/next-14-0-2-domino-build-error-bug-dylymw (I encourage downloading the app and running locally, as the resources are quite constrained).

As said in earlier comments, this is an issue with domino, not with turndown. In this sandbox app, turndown is required as just a dependency of remirror, the module defined as a dependency of the app (even not using the markdown string handler, which is what actually needs turndown).

LuisGilGB avatar Nov 28 '23 15:11 LuisGilGB

Adding below snippets in package.json works fix the issue for me

  "resolutions": {
    "domino": "Haringat/domino#2721294c75334ece635dfc72cad0a3dede7391fb"
  }

CleanShot 2024-02-08 at 20 58 54

datduyng avatar Feb 09 '24 04:02 datduyng

The package https://github.com/fgnass/domino that causes this error seems to be no longer maintained, so there is no hope that it will be fixed. If a DOM is needed from this package, perhaps https://github.com/capricorn86/happy-dom could be a lightweight alternative to JSDOM? I'd love to help and test it, but I'd like to know if there's any interest in getting rid of this problem at all?

In the meantime, I've switched to https://github.com/crosstype/node-html-markdown as a workaround. It's pretty basic and also not up to date, but at least it works on AWS Lambda.

zirkelc avatar Mar 19 '24 14:03 zirkelc