gpt4 book ai didi

javascript - 未捕获 您必须使用 Parse.initialize 指定一个 key

转载 作者:行者123 更新时间:2023-11-28 19:00:00 25 4
gpt4 key购买 nike

我已经使用 Parse 大约三个月了,但已经开始了一个新的应用程序。我使用的是 Parse 1.4.2 js sdk。

我在一个单独的文件中有一些代码正在向数据库发出请求。该文件包含在 main.js 文件中。

当我尝试部署(使用 1.4.2 sdk)时,我收到错误:

Uploading source files
Uploading recent changes to scripts...
The following files will be uploaded:
/Users/aaron/dev/Familiar/cloud/main.js
/Users/aaron/dev/Familiar/cloud/user.js
/Users/aaron/dev/Familiar/cloud/verification.js
Finished uploading files
Uncaught You must specify a key using Parse.initialize.

如果我尝试使用最新的 sdk 进行部署,则会收到错误:

Uploading source files
Uploading recent changes to scripts...
The following files will be uploaded:
/Users/aaron/dev/Familiar/cloud/verification.js
Finished uploading files
TypeError: Object #<Object> has no method 'request'
at Object.ajaxMod [as ajax] (<anonymous>:925:19)
at e.<anonymous> (Parse.js:13:25717)
at e.s (Parse.js:12:26759)
at Parse.js:12:27145
at i (Parse.js:12:27100)
at e.n.value (Parse.js:12:27130)
at Object.y.request (Parse.js:13:25644)
at Object.u.default.setQueryController.find (Parse.js:13:6132)
at e.a.value (Parse.js:13:76)
at e.<anonymous> (verification.js:18:38)

如果我注释掉所有 verification.js 它将上传,但取消注释后我会收到错误。我的其他工作应用程序从不调用Parse.initialize。为什么现在才要求它?

目录结构:

├── cloud
│   ├── comment.js
│   ├── lib
│   │   ├── config.js
│   │   ├── helpers.js
│   │   └── md5.js
│   ├── main.js
│   ├── user.js
│   └── verification.js
├── config
│   └── global.json
└── public
└── index.html

ma​​in.js

require("cloud/user.js");
require("cloud/comment.js");
require("cloud/verification.js");

verification.js

var conf = require("cloud/lib/config.js").conf;
var helpers = require("cloud/lib/helpers.js");

function createSmsVerification(user) {
return getUserSmsVerification(user)
.then(function (verification) {
var verificationQuery = new Parse.Query("Verification");
return verificationQuery.first(); <-- this is the line causing the error
})
.then(function (verification) {
return verification;
}, function (error) {
return Parse.Promise.error("createSmsVerification - " + error.message);
});
}
exports.createSmsVerification = createSmsVerification();

function getUserSmsVerification(user) {
return Parse.Promise.as();
}

user.js

var helpers         = require("cloud/lib/helpers.js"),
conf = require("cloud/lib/config.js").conf,
sms = require("cloud/sms.js"),
verification = require("cloud/verification.js");


Parse.Cloud.define("register", function(request, response){
Parse.Cloud.useMasterKey();
var phoneNumber = request.params.phoneNumber;
var user;
var userQuery = new Parse.Query(Parse.User);
userQuery.equalTo("username", phoneNumber);

return userQuery
.first(function(userResult){
if(!helpers.isDefined(userResult)){
userResult = createNewUser(phoneNumber);
}else{
userResult.set("smsVerified", false);
}
return userResult.save();
})
.then(function(userResult){
user = userResult;
return verification.createSmsVerification(user);
})
.then(function(){
response.success();
}, function (error){
console.error("register - " + error.message);
response.error(error.message);
});
});

function createNewUser(phoneNumber){
var newUser = new Parse.User();
newUser.set("username", helpers.phoneToUsername(phoneNumber));
newUser.set("password", helpers.generatePassword(phoneNumber));
newUser.set("smsVerified", false);
return newUser;
}

最佳答案

我遇到了同样的问题,并且发现每当我尝试在全局级别调用函数时都会遇到相同的错误。我唯一一次能够调用函数是在其他函数的范围内。

关于您的代码,我想您正在尝试导出函数本身,例如

exports.createSmsVerification = createSmsVerification;

您拥有的代码:

exports.createSmsVerification = createSmsVerification();

实际上调用该函数并导出结果。

关于javascript - 未捕获 您必须使用 Parse.initialize 指定一个 key ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32778985/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com