docs(troubleshooting): add workarounds for code transpilation (#3399)

References #1665
This commit is contained in:
Sebastián Gurin 2018-10-25 15:26:55 -03:00 committed by Andrey Lushnikov
parent cf8c62e835
commit fae441cd42

View File

@ -282,3 +282,15 @@ AWS Lambda [limits](https://docs.aws.amazon.com/lambda/latest/dg/limits.html) de
- https://github.com/adieuadieu/serverless-chrome/blob/master/docs/chrome.md (tracks the latest Chromium snapshots) - https://github.com/adieuadieu/serverless-chrome/blob/master/docs/chrome.md (tracks the latest Chromium snapshots)
- https://github.com/universalbasket/aws-lambda-chrome - https://github.com/universalbasket/aws-lambda-chrome
- https://github.com/Kikobeats/aws-lambda-chrome - https://github.com/Kikobeats/aws-lambda-chrome
## Code Transpilation Issues
If you are using a JavaScript transpiler like babel or TypeScript, calling `evaluate()` with an async function might not work. This is because while `puppeteer` uses `Function.prototype.toString()` to serialize functions while transpilers could be changing the output code in such a way it's incompatible with `puppeteer`.
Some workarounds to this problem would be to instruct the transpiler not to mess up with the code, for example, configure TypeScript to use latest ecma version (`"target": "es2018"`). Another workaround could be using string templates instead of functions:
```js
await page.evaluate(`(async() => {
console.log('1');
})()`);
```