我不确定以下错误是什么意思(底部完全错误)

TypeError: Cannot create proxy with a non-object as target or handler


我现在正在做什么,仅仅是通过创建config.js文件进行的基本操作

// The primary purpode of this file to help new comers with configuring environment.
const functions = require('firebase-functions')
const config = functions.config()

console.log(config)

const intialConfig = {
  DB_HOST: config.DB_HOST || 'localhost',
  DB_USER: config.DB_USER || 'root',
  DB_PASSWORD: config.DB_PASSWORD || 'root',
  DB_DATABASE: config.DB_DATABASE || 'database',
}


module.exports = intialConfig


然后初始化我的sql

// Intializing SQL here
const mysql = require('mysql')
const config = require('./../../config')

const pool = mysql.createPool({
  host: config.DB_HOST,
  user: config.DB_USER,
  password: config.DB_PASSWORD,
  database: config.DB_DATABASE,
});


// Checking if it was connected sucessfully or not on server startup
pool.getConnection((err, connection) => {
  if (err) {
    console.error('error connecting: ' + err);
    return
  }
  console.log('connected as id ' + connection.threadId);
  connection.release();
  return;
});


console.log(config)将其记录在控制台中(在第一个代码段中)

 { CLIENT_URL: [ 'http://localhost:3000' ],
>    DB_USER: 'root',
>    DB_PASSWORD: 'password',
>    DB_HOST: 'localhost',
>    DB_DATABASE: 'vpark' }


知道我在这里可能做错了什么吗?

更新:完全错误

TypeError: Cannot create proxy with a non-object as target or handler
    at new Proxied (/Users/varunbindal/.nvm/versions/node/v10.15.3/lib/node_modules/firebase-tools/lib/emulator/functionsEmulatorRuntime.js:60:22)
    at Proxied.any [as anyValue] (/Users/varunbindal/.nvm/versions/node/v10.15.3/lib/node_modules/firebase-tools/lib/emulator/functionsEmulatorRuntime.js:475:20)
    at Object.get (/Users/varunbindal/.nvm/versions/node/v10.15.3/lib/node_modules/firebase-tools/lib/emulator/functionsEmulatorRuntime.js:67:33)
    at Object.<anonymous> (/Users/varunbindal/Desktop/Dating App/backend-self/functions/src/config.js:8:19)
    at Module._compile (module.js:653:30)
    at Object.Module._extensions..js (module.js:664:10)
    at Module.load (module.js:566:32)
    at tryModuleLoad (module.js:506:12)
    at Function.Module._load (module.js:498:3)
    at Module.require (module.js:597:17)


[更新:2]如果我这样做,

// The primary purpode of this file to help new comers with configuring environment.
const functions = require('firebase-functions')
const config = functions.config().CLIENT_URL
console.log(config)
const intialconfig = {
    DB_HOST: 'localhost',
    DB_USER: 'root',
    DB_PASSWORD: 'rohit123',
    DB_DATABASE: 'blendtale'
}

module.exports = intialconfig



它引发以下错误

Non-existent functions.config() value requested!
   - Path: "CLIENT_URL.Symbol(nodejs.util.inspect.custom)"
   - Learn more at https://firebase.google.com/docs/functions/local-emulator
⚠  Non-existent functions.config() value requested!
   - Path: "CLIENT_URL.inspect"
   - Learn more at https://firebase.google.com/docs/functions/local-emulator
⚠  Non-existent functions.config() value requested!
   - Path: "CLIENT_URL.inspect"
   - Learn more at https://firebase.google.com/docs/functions/local-emulator
⚠  Non-existent functions.config() value requested!
   - Path: "CLIENT_URL.Symbol(Symbol.toStringTag)"
   - Learn more at https://firebase.google.com/docs/functions/local-emulator
⚠  Non-existent functions.config() value requested!
   - Path: "CLIENT_URL.Symbol(Symbol.iterator)"
   - Learn more at https://firebase.google.com/docs/functions/local-emulator
⚠  Non-existent functions.config() value requested!
   - Path: "CLIENT_URL.Symbol(Symbol.toStringTag)"
   - Learn more at https://firebase.google.com/docs/functions/local-emulator
⚠  TypeError: clazz is not a constructor
    at noPrototypeIterator (internal/util/inspect.js:440:14)
    at formatRaw (internal/util/inspect.js:691:31)
    at formatValue (internal/util/inspect.js:511:10)
    at inspect (internal/util/inspect.js:191:10)
    at formatWithOptions (util.js:164:18)
    at Object.format (util.js:72:10)
    at Console.console.(anonymous function) [as log] (/Users/anilbhatia/Desktop/Dating App/backend-self/functions/node_modules/log-prefix/log-prefix.js:16:27)
    at Object.<anonymous> (/Users/anilbhatia/Desktop/Dating App/backend-self/functions/src/config.js:4:9)
    at Module._compile (internal/modules/cjs/loader.js:701:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:712:10)
⚠  We were unable to load your functions code. (see above)


我的runtimeconfig包含在哪里

{
    "CLIENT_URL": ["http://localhost:3000"],
    "DB_USER": "root",
    "DB_PASSWORD": "rohit123",
    "DB_HOST": "localhost",
    "DB_DATABASE": "blendtale"
}



本地提供的脚本(npm run serve-locally)如下所示

    "admin-keys": "export GOOGLE_APPLICATION_CREDENTIALS='./.keys/admin.keys.json'",
    "serve-locally": "npm run admin-keys && export dev=true && firebase emulators:start",

最佳答案

看来配置文件有问题。
尝试设置为:

{
    "configData": {
        "client_url": "http://localhost:3000",
        "db_user": "root",
        "db_password": "rohit123",
        "db_host": "localhost",
        "db_database": "blendtale"
    }
}


并像这样访问它:

    const functions = require('firebase-functions')
    const config = functions.config().configData

关于javascript - 无法使用非对象作为目标或处理程序创建代理,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/57969312/

10-16 20:53