gpt4 book ai didi

javascript - Sails.JS:TypeError:无法读取未定义的属性 'pkg'

转载 作者:行者123 更新时间:2023-11-30 20:58:34 25 4
gpt4 key购买 nike

尝试运行我的简单 Sails.JS 应用程序(包含 swaggerui)时,出现以下错误:

$ sails lift

info: Starting app...

debug: hookPath: DummyPath\Software\MyService\node_modules\sails-swagger\dist\api\hooks\swagger
debug: marlinspike (swagger): loading config from DummyPath\Software\MyService\node_modules\sails-swagger\dist\config
debug: marlinspike (swagger): loading Services from DummyPath\Software\MyService\node_modules\sails-swagger\dist\api\services...
warn: marlinspike (swagger): no Services found. skipping
debug: marlinspike (swagger): loading Models...
debug: marlinspike (swagger): loading Controllers...
debug: marlinspike (swagger): loading Policies...
warn: marlinspike (swagger): no Policies found. skipping
DummyPath\Software\MyService\node_modules\sails-swagger\dist\api\hooks\swagger\index.js:49
hook.doc = _libXfmr2['default'].getSwagger(_this.sails, _this.sails.config.swagger.pkg);
^

TypeError: Cannot read property 'pkg' of undefined
at DummyPath\Software\MyService\node_modules\sails-swagger\dist\api\hooks\swagger\index.js:49:91
at DummyPath\Software\MyService\node_modules\sails\lib\app\private\after.js:91:14
at DummyPath\Software\MyService\node_modules\sails\node_modules\async\lib\async.js:721:13
at DummyPath\Software\MyService\node_modules\sails\node_modules\async\lib\async.js:52:16
at done (DummyPath\Software\MyService\node_modules\sails\node_modules\async\lib\async.js:246:17)
at DummyPath\Software\MyService\node_modules\sails\node_modules\async\lib\async.js:44:16
at Sails.<anonymous> (DummyPath\Software\MyService\node_modules\sails\node_modules\async\lib\async.js:718:17)
at Sails.<anonymous> (DummyPath\Software\MyService\node_modules\sails\node_modules\async\lib\async.js:167:37)
at Object.onceWrapper (events.js:293:19)
at emitNone (events.js:86:13)
at Sails.emit (events.js:188:7)
at Sails.emitter.emit (DummyPath\Software\MyService\node_modules\sails\lib\app\private\after.js:50:11)
at sailsReady (DummyPath\Software\MyService\node_modules\sails\lib\app\lift.js:53:11)
at DummyPath\Software\MyService\node_modules\sails\node_modules\async\lib\async.js:721:13
at DummyPath\Software\MyService\node_modules\sails\node_modules\async\lib\async.js:52:16
at DummyPath\Software\MyService\node_modules\sails\node_modules\async\lib\async.js:269:32

npm install、npm uninstall sails 或 npm cache clear 不起作用。我已经尝试过重新安装 grunt-cli 并再次 sails-swagger ...这里有人有解决方案吗?

关于 github.com 的问题也开了……

最佳答案

使用 sails-swagger 时,您还必须在 sails 应用程序的配置目录中为 swagger 创建一个配置文件。此配置文件设置一个指向您的 sails 应用程序的 package.json 文件的 pkg 变量。

上面的错误基本上是说找不到属性 pkg,因此 swagger 将不起作用。

要解决这个问题,首先在config目录下创建一个名为swagger.js的文件。

然后在swagger.js文件中添加如下内容

module.exports.swagger = {
/**
* require() the package.json file for your Sails app.
*/
pkg: require('../package'),
ui: {
url: 'http://swaggerui.balderdash.io'
}
};

关于javascript - Sails.JS:TypeError:无法读取未定义的属性 'pkg',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47371782/

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