question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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:closed
  • Created 4 years ago
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

5reactions
samtsterncommented, Sep 20, 2019

@irohitb ah I found the issue. Your config is not valid. For example you have this config:

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

But you actually need to always be two-levels deep, for example this fails:

$ firebase functions:config:set db_user="root"

Error: Invalid argument, each config value must have a 2-part key (e.g. foo.bar)

So you’d want to make your config something like:

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

And then in your config.js file:

const functions = require('firebase-functions')
const config = functions.config().datingapp  // THIS LINE IS DIFFERENT
const dummyConfig = { ...config }

I was able to get your app to run using this:

$ npm run serve-locally

> functions@ serve-locally /tmp/tmp.6T1mQn6kjh/DatingApp-backend/functions
> npm run admin-keys && export dev=true && firebase emulators:start


> functions@ admin-keys /tmp/tmp.6T1mQn6kjh/DatingApp-backend/functions
> export GOOGLE_APPLICATION_CREDENTIALS='./.keys/admin.keys.json'

i  Starting emulators: ["functions","database","hosting"]
✔  functions: Using node@10 from host.
✔  functions: Emulator started at http://localhost:5001
i  database: Emulator logging to database-debug.log
✔  database: Emulator started at http://localhost:9000
i  database: For testing set FIREBASE_DATABASE_EMULATOR_HOST=localhost:9000
i  hosting: Serving hosting files from: public
✔  hosting: Local server: http://localhost:5000
✔  hosting: Emulator started at http://localhost:5000
i  functions: Watching "/tmp/tmp.6T1mQn6kjh/DatingApp-backend/functions" for Cloud Functions...
>  [2019-09-20T18:58:15.358Z] { client_url: 'http://localhost:3000',
>    db_user: 'root',
>    db_password: 'rohit123',
>    db_host: 'localhost',
>    db_database: 'blendtale' }
✔  functions[status]: http function initialized (http://localhost:5001/fir-dumpster/us-central1/status).
✔  functions[invite]: http function initialized (http://localhost:5001/fir-dumpster/us-central1/invite).
✔  All emulators started, it is now safe to connect.
>  [2019-09-20T18:58:15.400Z] error connecting: Error: connect ECONNREFUSED 127.0.0.1:3306
0reactions
irohitbcommented, Sep 20, 2019

@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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found