gpt4 book ai didi

javascript - meteor :ReferenceError:要求未定义

转载 作者:行者123 更新时间:2023-12-03 11:03:06 25 4
gpt4 key购买 nike

我已经安装了 meteorhacks:npm 并在packages.json {"apn": "1.6.2"} 中定义了 apn。但是,当我运行以下代码时,出现错误 ReferenceError: require is not Defined:

var apn = Npm.require('apn'),
path = Npm.require('path'),
apnOptions = Meteor.settings.apnOptions || {},
alertSound = apnOptions.sound || "alert.aiff",
apnConnection

// default apn connection options
apnOptions = _.extend({
cert: path.join(appRootPath, "private", "cert.pem"),
key: path.join(appRootPath, "private", "key.pem"),
}, apnOptions)
apnConnection = new apn.Connection(apnOptions)

完整的错误消息:

W20150116-23:30:51.097(2)? (STDERR)           
W20150116-23:30:51.100(2)? (STDERR) /Users/Mika/.meteor/packages/meteor-tool/.1.0.38.zbazwc++os.osx.x86_64+web.browser+web.cordova/meteor-tool-os.osx.x86_64/dev_bundle/server-lib/node_modules/fibers/future.js:173
W20150116-23:30:51.101(2)? (STDERR) throw(ex);
W20150116-23:30:51.101(2)? (STDERR) ^
W20150116-23:30:51.101(2)? (STDERR) ReferenceError: require is not defined
W20150116-23:30:51.102(2)? (STDERR) at app/node_modules/apn/lib/connection.js:1:49
W20150116-23:30:51.102(2)? (STDERR) at app/node_modules/apn/lib/connection.js:774:3
W20150116-23:30:51.106(2)? (STDERR) at /Users/Mika/Devaus/meteor/flashcards/.meteor/local/build/programs/server/boot.js:175:10
W20150116-23:30:51.107(2)? (STDERR) at Array.forEach (native)
W20150116-23:30:51.107(2)? (STDERR) at Function._.each._.forEach (/Users/Mika/.meteor/packages/meteor-tool/.1.0.38.zbazwc++os.osx.x86_64+web.browser+web.cordova/meteor-tool-os.osx.x86_64/dev_bundle/server-lib/node_modules/underscore/underscore.js:79:11)
W20150116-23:30:51.107(2)? (STDERR) at /Users/Mika/Devaus/meteor/flashcards/.meteor/local/build/programs/server/boot.js:86:5

我的仓库:https://github.com/mvaisanen/flashcards

最佳答案

对于通过 meteorhacks:npm 加载的包,使用 Meteor.npmRequire 代替 Npm.require 。例如:

var apn = Meteor.npmRequire('apn');
var path = Npm.require('path');

另请注意,需要 npm 包只能在服务器上运行,因此请确保代码位于您的 /server 目录中或由 Meteor.isServer 保护。

关于javascript - meteor :ReferenceError:要求未定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27993227/

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