当我尝试为Dialogflow项目部署客户端代码时,出现以下错误。
Error: Error occurred while parsing your function triggers.
Error: ENOENT: no such file or directory, open 'c:\Projects\config.json'
at Object.fs.openSync (fs.js:646:18)
at Object.fs.readFileSync (fs.js:551:33)
at Object.exports.getConfig (c:\Projects\my_project\functions\my_utilities.js:10:18)
at Object.<anonymous> (c:\Projects\my_project\functions\index.js:10:24)
at Module._compile (module.js:652:30)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
at Function.Module._load (module.js:497:3)
at Module.require (module.js:596:17)
我的目录结构如下。
config.json
/functions
index.jx
my_utilities.js
我的my_utilities.js文件就是这样。
'use strict'
const moment = require('moment')
const fs = require('fs')
exports.getDatePlus = function(value)
{
return moment().add(value,'days').format('L');
}
exports.getConfig = function(path){
const raw = fs.readFileSync(path)
return JSON.parse(raw)
}
而我的index.js使用这样的my_utilities。
// The Cloud Functions for Firebase SDK to create Cloud Functions and setup triggers.
const functions = require('firebase-functions');
//var firebaseAuth = require("firebase-auth");
var firebaseClient = require('firebase-client');
var moment = require('moment');
const MyUtils = require('./my_utilities');
const Zoho = require('./zoho')
const Config = MyUtils.getConfig('../config.json')
这是我的firebase.json
{
"functions": {
"predeploy": [
"npm --prefix \"$RESOURCE_DIR\" run lint"
]
}
}
如果将配置文件移动到功能目录,则会收到此错误。
错误:解析函数触发器时发生错误。
Error: ENOENT: no such file or directory, open 'c:\Projects\myproject\config.json'
at Object.fs.openSync (fs.js:646:18)
如果两个目录中都有config.json文件,它将进行部署,但这不是解决方案。必须有一种方法来包含配置信息,而不必将其散布开来。