Skip to content
This repository has been archived by the owner on Nov 4, 2024. It is now read-only.

dynamic import in puppeteer #762

Closed
Jamesernator opened this issue Mar 24, 2019 · 2 comments
Closed

dynamic import in puppeteer #762

Jamesernator opened this issue Mar 24, 2019 · 2 comments
Labels

Comments

@Jamesernator
Copy link
Contributor

Because esm transforms import() in all source locations this can break the use of import() that occurs with a puppeteer function. This has made it impossible to test my library with ava as it depends on being able to use import() inside page.evaluate.

A simple minimal example that breaks:

import puppeteer from "puppeteer";

async function main() {
  const browser = await puppeteer.launch()
  const page = await browser.newPage()
  const values = await page.evaluate(async () => {
    const _ = await import("https://unpkg.com/lodash-es@4.17.11/lodash.js?module")
    return _.zip([1,2,3,4], [5,6,7,8])
  })
  console.log(values)
  await browser.close()
}

main()

With --experimental-modules this works fine but with -r esm it fails with Error: Evaluation failed: ReferenceError: _c72‍ is not defined.

Probably the best way to fix it would be to patch functions .toString method so that it returns the original source text rather than the transformed source text.

@jdalton
Copy link
Member

jdalton commented Mar 24, 2019

Hi @Jamesernator!

Wrapping functions is something I could do but I want to avoid until there’s more demand. Until then esm may not be the best thing for your situation.

Update:

Since puppeteer is a popular utility, I'll investigate esm shimming puppeteer to scrub its strings.

Update:

Patch c231404; 38a6b7d

Update:

esm v3.2.21 is released 🎉

@Jamesernator
Copy link
Contributor Author

Awesome thanks for this.

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

No branches or pull requests

2 participants