halfzebra / create-elm-app

🍃 Create Elm apps with zero configuration

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Ports code does not support Async/Await

maxwolff opened this issue · comments

Adding an async function to index.js such as

const f = async () => {
	await new Promise(r => setTimeout(r, 2000));
}

Causes elm-app start to fail with

./src/index.js
Module not found: Can't resolve '@babel/runtime/regenerator'

Node 14.9, 1.22, OS X, Chrome,

which elm-app => node/v10.18.1/bin/elm-app
yarn doesnt have a ls for global afaik

Hacking around this by transpiling w babel manually, npx babel src/index2.js --out-file src/index.js --plugins async-to-promises

I suspect adding some babel plugins in the webpack config somewhere around here would do it.

Another clue: https://babeljs.io/docs/en/babel-plugin-transform-runtime#technical-details

The transform-runtime transformer plugin does three things:

Automatically requires @babel/runtime/regenerator when you use generators/async functions (toggleable with the regenerator option).

Though it looks like transform-runtime is installed and regenerator should be part of it.

I was able to get rid of this error by specifying a browserslist of current browsers inside package.json.

But if you want your app to work on old browsers that won't help you I'm afraid.

thx, at some point we gotta leave those old browsers behind :)

I just ran into this as well. Is setting a browerlist in each individual project the right solution? Can that be added to create-elm-app itself, or is there a better solution to this?