Taro: Taro 2.0.0-beta. 2报`regeneratorRuntime is not defined`错,跟async-await有关,在微信开发者工作上。

Created on 15 Nov 2019  ·  11Comments  ·  Source: NervJS/taro

问题描述

复现步骤

// app.js
import Taro, { Component } from '@tarojs/taro'
import '@tarojs/async-await'
import { Provider } from '@tarojs/redux'

// 源码
async getLoginInfo() {
      const { loginStatus, userInfo } = await this.getState()
      return {
        loginStatus,
        userInfo
      }
    },

// 编译后
var _ref = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee() {
        var _ref2, loginStatus, userInfo;
        return regeneratorRuntime.wrap(function _callee$(_context) {}
})

期望行为

regeneratorRuntime从global中正确引入

报错信息


regeneratorRuntime is not defined

系统信息


Taro CLI 2.0.0-beta.2 environment info:
System:
OS: macOS 10.15
Shell: 5.7.1 - /bin/zsh
Binaries:
Node: 10.14.1 - ~/.nvm/versions/node/v10.14.1/bin/node
Yarn: 1.17.3 - ~/.nvm/versions/node/v10.14.1/bin/yarn
npm: 6.12.0 - ~/.nvm/versions/node/v10.14.1/bin/npm
npmPackages:
@tarojs/async-await: 1.3.25 => 1.3.25
@tarojs/components: 1.3.25 => 1.3.25
@tarojs/plugin-babel: 1.3.25 => 1.3.25
@tarojs/plugin-csso: 1.3.25 => 1.3.25
@tarojs/plugin-stylus: 1.3.25 => 1.3.25
@tarojs/plugin-uglifyjs: 1.3.25 => 1.3.25
@tarojs/redux: 1.3.25 => 1.3.25
@tarojs/redux-h5: 1.3.25 => 1.3.25
@tarojs/router: 1.3.25 => 1.3.25
@tarojs/taro: 1.3.25 => 1.3.25
@tarojs/taro-alipay: 1.3.25 => 1.3.25
@tarojs/taro-h5: 1.3.25 => 1.3.25
@tarojs/taro-swan: 1.3.25 => 1.3.25
@tarojs/taro-tt: 1.3.25 => 1.3.25
@tarojs/taro-weapp: 1.3.25 => 1.3.25
@tarojs/webpack-runner: 1.3.25 => 1.3.25
eslint-config-taro: 1.3.25 => 1.3.25
eslint-plugin-taro: 1.3.25 => 1.3.25
nerv-devtools: ^1.5.5 => 1.5.5
nervjs: ^1.5.5 => 1.5.5
stylelint-config-taro-rn: 1.3.25 => 1.3.25
stylelint-taro-rn: 1.3.25 => 1.3.25

补充信息

如果您有功能上的建议,可以提到 FeatHub

使用上的问题,欢迎在「Taro 社区」一起交流

question

Most helpful comment

@Garfield550 按照你说的,我把多余的配置给注释掉了,依旧报错。

// config.js
const alias = require('./alias')

const config = {
  projectName: 'taro-framework',
  date: '2019-11-2',
  designWidth: 750,
  deviceRatio: {
    '640': 2.34 / 2,
    '750': 1,
    '828': 1.81 / 2
  },
  sourceRoot: 'src',
  outputRoot: 'dist',
  // plugins: {
  //   babel: {
  //     sourceMap: true,
  //     presets: [
  //       ['env', {
  //         modules: false
  //       }]
  //     ],
  //     plugins: [
  //       'transform-decorators-legacy',
  //       'transform-class-properties',
  //       'transform-object-rest-spread'
  //     ]
  //   }
  // },
  defineConstants: {
    'process.env.SERVER_ENV': JSON.stringify(process.env.SERVER_ENV),
    'process.env.APPID_ENV': JSON.stringify(process.env.APPID_ENV),
    'process.env.MOCK': JSON.stringify(process.env.MOCK),
  },
  alias,
  copy: {
    patterns: [
    ],
    options: {
    }
  },
  mini: {
    // module: {
    //   postcss: {
    //     autoprefixer: {
    //       enable: true,
    //       config: {
    //         browsers: [
    //           'last 3 versions',
    //           'Android >= 4.1',
    //           'ios >= 8'
    //         ]
    //       }
    //     },
    //     pxtransform: {
    //       enable: true,
    //       config: {

    //       }
    //     },
    //     url: {
    //       enable: true,
    //       config: {
    //         limit: 10240 // 设定转换尺寸上限
    //       }
    //     },
    //     cssModules: {
    //       enable: false, // 默认为 false,如需使用 css modules 功能,则设为 true
    //       config: {
    //         namingPattern: 'module', // 转换模式,取值为 global/module
    //         generateScopedName: '[name]__[local]___[hash:base64:5]'
    //       }
    //     }
    //   }
    // }
  },
  h5: {
    publicPath: '/',
    staticDirectory: 'static',
  //   module: {
  //     postcss: {
  //       autoprefixer: {
  //         enable: true,
  //         config: {
  //           browsers: [
  //             'last 3 versions',
  //             'Android >= 4.1',
  //             'ios >= 8'
  //           ]
  //         }
  //       },
  //       cssModules: {
  //         enable: false, // 默认为 false,如需使用 css modules 功能,则设为 true
  //         config: {
  //           namingPattern: 'module', // 转换模式,取值为 global/module
  //           generateScopedName: '[name]__[local]___[hash:base64:5]'
  //         }
  //       }
  //     }
  //   }
  }
}

module.exports = function (merge) {
  if (process.env.NODE_ENV === 'development') {
    return merge({}, config, require('./dev'))
  }
  return merge({}, config, require('./prod'))
}

截图:https://n1image.hjfile.cn/res7/2019/11/15/18686ed2c20f6ed728710797bcdb3635.png

All 11 comments

CC @luckyadam

欢迎提交 Issue~

如果你提交的是 bug 报告,请务必遵循 Issue 模板的规范,尽量用简洁的语言描述你的问题,最好能提供一个稳定简单的复现。🙏🙏🙏

如果你的信息提供过于模糊或不足,或者已经其他 issue 已经存在相关内容,你的 issue 有可能会被关闭。

Good luck and happy coding~

你的依赖还是 1.3.25

我在尝试,我刚刚都换到了beta版本,还是有问题。

Taro CLI 2.0.0-beta.2 environment info:
System:
OS: macOS 10.15
Shell: 5.7.1 - /bin/zsh
Binaries:
Node: 10.14.1 - ~/.nvm/versions/node/v10.14.1/bin/node
Yarn: 1.17.3 - ~/.nvm/versions/node/v10.14.1/bin/yarn
npm: 6.12.0 - ~/.nvm/versions/node/v10.14.1/bin/npm
npmPackages:
@tarojs/async-await: ^2.0.0-beta.2 => 2.0.0-beta.2
@tarojs/components: ^2.0.0-beta.2 => 2.0.0-beta.2
@tarojs/plugin-babel: ^2.0.0-beta.2 => 2.0.0-beta.2
@tarojs/plugin-csso: ^2.0.0-beta.2 => 2.0.0-beta.2
@tarojs/plugin-stylus: ^2.0.0-beta.2 => 2.0.0-beta.2
@tarojs/plugin-uglifyjs: ^2.0.0-beta.2 => 2.0.0-beta.2
@tarojs/redux: ^2.0.0-beta.2 => 2.0.0-beta.2
@tarojs/redux-h5: ^2.0.0-beta.2 => 2.0.0-beta.2
@tarojs/router: ^2.0.0-beta.2 => 2.0.0-beta.2
@tarojs/taro: ^2.0.0-beta.2 => 2.0.0-beta.2
@tarojs/taro-alipay: ^2.0.0-beta.2 => 2.0.0-beta.2
@tarojs/taro-h5: ^2.0.0-beta.2 => 2.0.0-beta.2
@tarojs/taro-swan: ^2.0.0-beta.2 => 2.0.0-beta.2
@tarojs/taro-tt: ^2.0.0-beta.2 => 2.0.0-beta.2
@tarojs/taro-weapp: ^2.0.0-beta.2 => 2.0.0-beta.2
@tarojs/webpack-runner: ^2.0.0-beta.2 => 2.0.0-beta.2
eslint-config-taro: ^2.0.0-beta.2 => 2.0.0-beta.2
eslint-plugin-taro: ^2.0.0-beta.2 => 2.0.0-beta.2
nerv-devtools: ^1.5.5 => 1.5.5
nervjs: ^1.5.5 => 1.5.5
stylelint-config-taro-rn: ^2.0.0-beta.2 => 2.0.0-beta.2
stylelint-taro-rn: ^2.0.0-beta.2 => 2.0.0-beta.2

感觉可能跟我的配置有关系,提一下我的配置

const alias = require('./alias')

const config = {
  projectName: 'taro-framework',
  date: '2019-11-2',
  designWidth: 750,
  deviceRatio: {
    '640': 2.34 / 2,
    '750': 1,
    '828': 1.81 / 2
  },
  sourceRoot: 'src',
  outputRoot: 'dist',
  plugins: {
    babel: {
      sourceMap: true,
      presets: [
        ['env', {
          modules: false
        }]
      ],
      plugins: [
        'transform-decorators-legacy',
        'transform-class-properties',
        'transform-object-rest-spread'
      ]
    }
  },
  defineConstants: {
    'process.env.SERVER_ENV': JSON.stringify(process.env.SERVER_ENV),
    'process.env.APPID_ENV': JSON.stringify(process.env.APPID_ENV),
    'process.env.MOCK': JSON.stringify(process.env.MOCK),
  },
  alias,
  copy: {
    patterns: [
    ],
    options: {
    }
  },
  mini: {
    module: {
      postcss: {
        autoprefixer: {
          enable: true,
          config: {
            browsers: [
              'last 3 versions',
              'Android >= 4.1',
              'ios >= 8'
            ]
          }
        },
        pxtransform: {
          enable: true,
          config: {

          }
        },
        url: {
          enable: true,
          config: {
            limit: 10240 // 设定转换尺寸上限
          }
        },
        cssModules: {
          enable: false, // 默认为 false,如需使用 css modules 功能,则设为 true
          config: {
            namingPattern: 'module', // 转换模式,取值为 global/module
            generateScopedName: '[name]__[local]___[hash:base64:5]'
          }
        }
      }
    }
  },
  h5: {
    publicPath: '/',
    staticDirectory: 'static',
    module: {
      postcss: {
        autoprefixer: {
          enable: true,
          config: {
            browsers: [
              'last 3 versions',
              'Android >= 4.1',
              'ios >= 8'
            ]
          }
        },
        cssModules: {
          enable: false, // 默认为 false,如需使用 css modules 功能,则设为 true
          config: {
            namingPattern: 'module', // 转换模式,取值为 global/module
            generateScopedName: '[name]__[local]___[hash:base64:5]'
          }
        }
      }
    }
  }
}

module.exports = function (merge) {
  if (process.env.NODE_ENV === 'development') {
    return merge({}, config, require('./dev'))
  }
  return merge({}, config, require('./prod'))
}

是有问题,
plugins 字段不再包含 babel 等配置
mini 字段不再包含 module 字段
h5 字段不再包含 module 字段

1.3.25也有这个问题,我刚升级上来,就遇到这个问题。

@Garfield550 按照你说的,我把多余的配置给注释掉了,依旧报错。

// config.js
const alias = require('./alias')

const config = {
  projectName: 'taro-framework',
  date: '2019-11-2',
  designWidth: 750,
  deviceRatio: {
    '640': 2.34 / 2,
    '750': 1,
    '828': 1.81 / 2
  },
  sourceRoot: 'src',
  outputRoot: 'dist',
  // plugins: {
  //   babel: {
  //     sourceMap: true,
  //     presets: [
  //       ['env', {
  //         modules: false
  //       }]
  //     ],
  //     plugins: [
  //       'transform-decorators-legacy',
  //       'transform-class-properties',
  //       'transform-object-rest-spread'
  //     ]
  //   }
  // },
  defineConstants: {
    'process.env.SERVER_ENV': JSON.stringify(process.env.SERVER_ENV),
    'process.env.APPID_ENV': JSON.stringify(process.env.APPID_ENV),
    'process.env.MOCK': JSON.stringify(process.env.MOCK),
  },
  alias,
  copy: {
    patterns: [
    ],
    options: {
    }
  },
  mini: {
    // module: {
    //   postcss: {
    //     autoprefixer: {
    //       enable: true,
    //       config: {
    //         browsers: [
    //           'last 3 versions',
    //           'Android >= 4.1',
    //           'ios >= 8'
    //         ]
    //       }
    //     },
    //     pxtransform: {
    //       enable: true,
    //       config: {

    //       }
    //     },
    //     url: {
    //       enable: true,
    //       config: {
    //         limit: 10240 // 设定转换尺寸上限
    //       }
    //     },
    //     cssModules: {
    //       enable: false, // 默认为 false,如需使用 css modules 功能,则设为 true
    //       config: {
    //         namingPattern: 'module', // 转换模式,取值为 global/module
    //         generateScopedName: '[name]__[local]___[hash:base64:5]'
    //       }
    //     }
    //   }
    // }
  },
  h5: {
    publicPath: '/',
    staticDirectory: 'static',
  //   module: {
  //     postcss: {
  //       autoprefixer: {
  //         enable: true,
  //         config: {
  //           browsers: [
  //             'last 3 versions',
  //             'Android >= 4.1',
  //             'ios >= 8'
  //           ]
  //         }
  //       },
  //       cssModules: {
  //         enable: false, // 默认为 false,如需使用 css modules 功能,则设为 true
  //         config: {
  //           namingPattern: 'module', // 转换模式,取值为 global/module
  //           generateScopedName: '[name]__[local]___[hash:base64:5]'
  //         }
  //       }
  //     }
  //   }
  }
}

module.exports = function (merge) {
  if (process.env.NODE_ENV === 'development') {
    return merge({}, config, require('./dev'))
  }
  return merge({}, config, require('./prod'))
}

截图:https://n1image.hjfile.cn/res7/2019/11/15/18686ed2c20f6ed728710797bcdb3635.png

@luckyadam @Garfield550 我新建了一个Taro项目,使用async-await,立马报错。

getLoginInfo = async () => {
    const settings = await Taro.getSetting()
    console.log('settings :', settings)
  }

Demo地址:https://github.com/shenghanqin/taro-new-feature/blob/master/src/pages/index/index.jsx

2.0.0-beta.3 试一下?https://github.com/NervJS/taro/issues/4837#issuecomment-555030425

按照 #4837 中提及的,还得修改config的babel配置才可以解决。当然我已经用beta4上config修改配置后解决了。

Was this page helpful?
0 / 5 - 0 ratings