天天看點

RN 打包運作報錯 “cannot find variable atob”

問題

在開發模式下,開啟 Remote Debug 運作良好,關閉Remote Debug或者打包運作,則報錯 “cannot find variable atob”.

解決

需要添加pollify

  1. 安裝buffer包
    npm install --save buffer
               
  2. 添加atob pollify

    根目錄建立

    pollify.js

    global.Buffer = require('buffer').Buffer;
    if (typeof atob === 'undefined') {
    	global.atob = function (b64Encoded) {
    	    return new Buffer(b64Encoded, 'base64').toString('binary');
    	};
    }
               

    index.js

    第一行添加
    import './polyfill';
    import {AppRegistry} from 'react-native';
    import App from './App';
               

繼續閱讀