集成Parse-SDK-JS以响应应用程序

问题描述

我尝试用Google搜索一些指南或教程,但没有找到任何指南。有什么方法可以将与Android和iOS方式相同的Parse SDK集成到我的本地应用程序中?因为我尝试集成Parse-SDK-JS,但现在我的应用无法正常工作,因此崩溃,并显示错误Error: Unable to resolve module crypto from node_modules\parse\node_modules\crypto-js\core.js: crypto Could not be found within the project.'

我的代码

parse.ts:

 // In a React Native application
import Parse,{ Error } from 'parse';
// On React Native >= 0.50 and Parse >= 1.11.0,set the Async
import { AsyncStorage } from 'react-native';

export const initParse = () => {
  Parse.setAsyncStorage(AsyncStorage);
  Parse.initialize('xxxxxxxxxxxxxxxxxxxxxxxxxxx'); //APP_ID
  Parse.serverURL = 'https://xxx.herokuapp.com/parse'; //HEROKU URI SERVER
};

export const testCreate = () => {
  const Gamescore = Parse.Object.extend('Gamescore');
  const gamescore = new Gamescore();

  gamescore.set('score',1337);
  gamescore.set('playerName','Sean Plott');
  gamescore.set('cheatMode',false);

  gamescore.save().then(
    (gamescore: any) => {
      // Execute any logic that should take place after the object is saved.
      alert('New object created with objectId: ' + gamescore.id);
    },(error: Error) => {
      // Execute any logic that should take place if the save fails.
      // error is a Parse.Error with an error code and message.
      alert('Failed to create new object,with error code: ' + error.message);
    },);
};

index.js:


/**
 * @format
 */

import {
    AppRegistry
} from 'react-native';
import {
    initParse
} from './src/library/parse/parse';
import App from './App';
import {
    name as appName
} from './app.json';

initParse();

AppRegistry.registerComponent(appName,() => App);

解决方法

您需要从parse/react-native.js导入Parse。应该是这样的:

import Parse,{ Error } from 'parse/react-native.js';