Closed Mizumaki closed 5 years ago
@Mizumaki This happens because production webpack config doesn't process ES6 code.
As a quick fix I would suggest the following:
babel-polyfill
:npm install --save @babel/polyfill
node_modules/react-scripts/config/polyfills.js
'use strict';
if (typeof Promise === 'undefined') {
// Rejection tracking prevents a common issue where React gets into an
// inconsistent state due to an error, but it gets swallowed by a Promise,
// and the user has no idea what causes React's erratic future behavior.
require('promise/lib/rejection-tracking').enable();
window.Promise = require('promise/lib/es6-extensions.js');
}
require('babel-polyfill'); <-- Add this line
// fetch() polyfill for making API calls.
require('whatwg-fetch');
@Emerkof The advice you provide is really helpful.
This happens because production webpack config doesn't process ES6 code.
In fact, adding polyfill is not working and the error still occurs.
I also tried to add require("@babel/polyfill");
which is the process suggested
in babel official docs, but it's also not working.
However, thanks to your advice which provides the problem is webpack config, I notice trying updating react-scripts to a newer version (v2.0.5) might be helpful and it works well.
I'm really appreciate for your advice, thanks😆
upgrade react-scripts
works, thanks @Mizumaki
yarn add react-scripts@2.0.5
When I execute
yarn build
in client folder , this error always occurred.And the code in truffle-contract is this.
How can I fix this?