babel/preset-env ReferenceError : regeneratorRuntime is not defined
阿新 • • 發佈:2018-12-15
> [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.<anonymous> (/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