babel/preset-env ReferenceError : regeneratorRuntime is not defined

> [email protected] start /home/lmx/Workspace/react-ssr
> node ./build/bundle.js

webpack:///./src/index.js?:18
  regeneratorRuntime.mark(function _callee(ctx) {
  ^

ReferenceError: regeneratorRuntime is not defined
    at eval (webpack:///./src/index.js?:18:3)
    at eval (webpack:///./src/index.js?:36:2)
    at Object../src/index.js (/home/lmx/Workspace/react-ssr/build/bundle.js:96:1)
    at __webpack_require__ (/home/lmx/Workspace/react-ssr/build/bundle.js:20:30)
    at /home/lmx/Workspace/react-ssr/build/bundle.js:84:18
    at Object. (/home/lmx/Workspace/react-ssr/build/bundle.js:87:10)
    at Module._compile (module.js:652:30)
    at Object.Module._extensions..js (module.js:663:10)
    at Module.load (module.js:565:32)
    at tryModuleLoad (module.js:505:12)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] start: `node ./build/bundle.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:

包含 transform-regenerator 插件是因为定义了预设支持的所有浏览器的最后两个版本。

presets: ['@babel/preset-react', ['@babel/preset-env', {
    targets:{
        browsers: ['last 2 versions']
    }
}]]

如果想要解决这个问题,可以在项目的入口文件的顶部引入 babel-polyfill 包即可。

require("babel-polyfill")

记得在引入前,先安装一下依赖

npm install babel-polyfill --save-dev

参考:babel-preset-env@issues/112

你可能感兴趣的:(JavaScript,Node)