Cannot create proxy with a non-object as target or handler
See original GitHub issue[REQUIRED] Environment info
firebase-tools: 7.2.4
macOS: Mojave 10.14
[REQUIRED] Test case
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
And then initialising mysql
// 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;
});
Error
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)
[REQUIRED] Steps to reproduce
Above steps and then deploying by running following command
export GOOGLE_APPLICATION_CREDENTIALS='./.keys/admin.keys.json && export dev=true && firebase emulators:start --only functions
[REQUIRED] Expected behavior
It would copy my runtime environment variable
[REQUIRED] Actual behavior
it throws the following error
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)
Issue Analytics
- State:
- Created 4 years ago
- Comments:9 (5 by maintainers)
Top Results From Across the Web
ES6 proxy work-around for "TypeError: Cannot create proxy ...
"Uncaught TypeError: Cannot create proxy with a non-object as target or handler". var target = 5; var p = new Proxy(target, {} ...
Read more >Error: Cannot create proxy with a non-object as target or handler
Hi all, I am receiving this error in my plasmic instance. Any ideas of how this is resolved?
Read more >Proxy - JavaScript - MDN Web Docs
The Proxy object enables you to create a proxy for another object, which can intercept and redefine fundamental operations for that object.
Read more >Introduction to “Proxy” API for Metaprogramming in JavaScript
Else, TypeError: Cannot create proxy with a non-object as target or handler error is thrown. Creating a proxy around target doesn't prevent ...
Read more >Proxy and Reflect - The Modern JavaScript Tutorial
As a starting example, let's create a proxy without any traps: let target = {}; let proxy = new Proxy(target, {}); // empty...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@irohitb ah I found the issue. Your config is not valid. For example you have this config:
But you actually need to always be two-levels deep, for example this fails:
So you’d want to make your config something like:
And then in your
config.js
file:I was able to get your app to run using this:
@samtstern it just contains two endpoint and basic initialisation code (express, middleware and SQL). Can you have quick overview of it? if not, I will try to create a new separate project.