Skip to content
This repository has been archived by the owner on Sep 16, 2023. It is now read-only.

Puppeteer + ESM not working anymore #654

Closed
damianobarbati opened this issue Nov 3, 2018 · 6 comments
Closed

Puppeteer + ESM not working anymore #654

damianobarbati opened this issue Nov 3, 2018 · 6 comments
Labels

Comments

@damianobarbati
Copy link

@jdalton puppeteer + ESM combo is not working anymore and --experimental-modules flag is required => puppeteer/puppeteer#3382
It always worked fine until their 1.9.0 release.
Since ESM behaves like plain requires under the hood I was wondering whether this may be something to be investigated on ESM side rather than puppeteer side.

@jdalton
Copy link
Member

jdalton commented Nov 3, 2018

Thanks @damianobarbati!

I'll totally look into it! Do you have any ideas what the root issue could be?
The notes from the 1.9.0 release may provide a clue.

@jdalton jdalton added the bug label Nov 3, 2018
@damianobarbati
Copy link
Author

damianobarbati commented Nov 3, 2018

Do you have any ideas what the root issue could be?

Maybe! The guilty commit is this one (after investigating the changelog): puppeteer/puppeteer@5acf953

The error triggered:

(node:11730) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'on' of undefined
    at Function.addEventListener (../node_modules/puppeteer/lib/helper.js:165:13)

leads to this function:

function stringifyArgument(arg) {
      if (Helper.isString(arg) || Helper.isNumber(arg) || !arg)
        return JSON.stringify(arg);
      if (typeof arg === 'function') {
        let text = arg.toString().split('\n').map(line => line.trim()).join('');
        if (text.length > 20)
          text = text.substring(0, 20) + '…';
        return `"${text}"`;
      }
      const state = {};
      const keys = Object.keys(arg);
      for (const key of keys) {
        const value = arg[key];
        if (Helper.isString(value) || Helper.isNumber(value))
          state[key] = JSON.stringify(value);
      }
      const name = arg.constructor.name === 'Object' ? '' : arg.constructor.name; //<== OUCH!!!
      return name + JSON.stringify(state);
    }

Not sure about "who (is passing) what in arg": maybe that arg can be an "imported/required" module exporting a class and its constructor.name property is not correctly set when resolved by ESM? 🤔

And as always... thanks for your effort!!!

@jdalton
Copy link
Member

jdalton commented Nov 3, 2018

Thank you @damianobarbati!

Do you know what the result of name is?

@damianobarbati
Copy link
Author

damianobarbati commented Nov 3, 2018

@jdalton wait, that's not the problem (wrong code). Not sure anymore whether this is related to ESM or not, I'm posting what I found digging in the code on puppeteer issue before closing this.

@jdalton
Copy link
Member

jdalton commented Nov 9, 2018

Patched 111328e.

@jdalton jdalton closed this as completed Nov 9, 2018
@ydnar
Copy link

ydnar commented Dec 18, 2018

When will this be released?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Development

No branches or pull requests

3 participants