skpm / sketch-module-web-view

A sketch module for creating an complex UI with a webview
MIT License
289 stars 62 forks source link

async/await does not work #145

Closed neoddish closed 4 years ago

neoddish commented 4 years ago

As this discussion metioned.

the async/await in my demo does not work if I did not npm install @babel/polyfill and add the code

module.exports = config => {
  config.entry = ['@babel/polyfill', config.entry];
}

into webpack.skpm.config.js.

After doing this, it works. However, every time I run the plugin again, the console throws:

@babel/polyfill is loaded more than once on this page. This is probably not desirable/intended and may have consequences if different versions of the polyfills are applied sequentially. If you do need to load the polyfill more than once, use @babel/polyfill/noConflict instead to bypass the warning.

lizheming commented 4 years ago

There has two ways to resolve your problem:

  1. install regenerator-runtime as devDependencies and add import 'regenerator-runtime'; at the first line in your command file.
  2. install @babel/plugin-transform-runtime as devDependencies and create .babelrc file with following content into root directory of your project:
    {
     "plugins": [
       [
         "@babel/plugin-transform-runtime",
         {
           "regenerator": true
         }
       ]
     ]
    }

I think the second is a good solution and open a pull request skpm/skpm#281 to resolve it. It will work well with default config after the pull request merged.