Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a recipe to transpile async functions #579

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions src/i18n/fr/docs/recipes.md
Original file line number Diff line number Diff line change
Expand Up @@ -272,3 +272,24 @@ Ensuite, dans votre fichier `index.html`, ajoutez une référence à votre point
```

C'est fait !

## Transpiler les fonctions async

Parcel utilise babel et fait un maximum sans configuration. Néanmoins, pour transpiler les fonctions [async](https://developer.mozilla.org/fr/docs/Web/JavaScript/Reference/Instructions/async_function), vous pouvez rajouter un fichier `.babelrc` avec ce contenu :

```json
{
"presets": [
"@babel/preset-env"
],
"plugins": [
["@babel/plugin-transform-runtime", {
"regenerator": true
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What are those lines for ? I think it is not required for @babel/preset-env to work well.

By the way I think it is related to this error parcel-bundler/parcel#2936 ? I've faced it too and can't find a way to fix it... is it the solution ?

Copy link
Author

@laruiss laruiss Apr 21, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @benavern, sorry for the delay.
It is to be able to transpile properly async functions.

Without it, I get this error in the console :

ReferenceError: regeneratorRuntime is not defined

And obviously the code does not work.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah ok. I have struggled with this error too but not with async functions. If I remember well this is when using a bundle (generated by parcel) as a dependancy in a project that uses parcel too.
And I don't have any async function in it.
If you wonna help on it: https://github.com/benavern/z-components

}]
]
}
```

Parcel installera tout seul pour vous les dépendances !

Vous pouvez désormais utiliser les fonctions async dans votre code.