browser.js:173未捕获错误:不支持process.binding

时间:2017-01-05 16:25:37

标签: javascript node.js reactjs request

一旦我添加使用request插件的代码块。我收到了这个错误。不知道为什么它的到来以及该怎么做。

通过url安装discussions,但尚未成功。

这是我的代码:

export function serviceCall(token, method, url, body) {
  return new Promise((resolve, reject) => {
    let start = new Date();
    let reqObj = {
      method,
      url: `${config.api}/${url}`,
      headers: {
        Authorization: token
      }
    };
    if (body) {
      reqObj.body = body;
      reqObj.json = true;
    }
    request(
      reqObj,
      function (error, response, body) {
        try {
          if (!error && (response.statusCode === 200 || response.statusCode === 201 || response.statusCode === 204)) {
            if (typeof body === 'object') {
              return resolve(body);
            }
            return resolve(JSON.parse(body));
          }
          // The error messages are actually getting sent in the body
          return reject(JSON.stringify(body));
        } catch (err) {
          reject(err);
        }
      }
    );
  });

错误:

browser.js:173 Uncaught Error: process.binding is not supported
    at Object.process.binding (browser.js:173)
    at Object.eval (util.js:3)
    at eval (util.js:1053)
    at Object.<anonymous> (bundle.js:6628)
    at __webpack_require__ (bundle.js:556)
    at fn (bundle.js:87)
    at eval (stream.js:6)
    at Object.<anonymous> (bundle.js:6700)
    at __webpack_require__ (bundle.js:556)
    at fn (bundle.js:87)

1 个答案:

答案 0 :(得分:0)

经过大量搜索后,我遇到了一个解决方案。此问题是由我在应用中使用的插件react-scripts之一引起的。将该插件更新到0.8.2的最新版本后,它对我有用。我将这个答案留给将来可能面临类似流行的人。

Reference