Nodejs-storage: ReferenceError: Invalid left-hand side in assignment

Created on 28 Jun 2019  路  8Comments  路  Source: googleapis/nodejs-storage

I am getting error when I import @google-cloud/storage in nodejs,

I have tried importing using:

const gcs = require('@google-cloud/storage');

`/home/devteam11/TRD/new-rest-api/node_modules/pify/index.js:3
const processFn = (fn, opts) =
^^^^^^^^^^

ReferenceError: Invalid left-hand side in assignment
at Module._compile (internal/modules/cjs/loader.js:720:23)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:787:10)
at Module.load (internal/modules/cjs/loader.js:643:32)
at Function.Module._load (internal/modules/cjs/loader.js:556:12)
at Module.require (internal/modules/cjs/loader.js:683:19)
at require (internal/modules/cjs/helpers.js:16:16)
at Object. (/home/devteam11/TRD/new-rest-api/node_modules/make-dir/index.js:4:14)
at Module._compile (internal/modules/cjs/loader.js:776:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:787:10)
at Module.load (internal/modules/cjs/loader.js:643:32)
at Function.Module._load (internal/modules/cjs/loader.js:556:12)
at Module.require (internal/modules/cjs/loader.js:683:19)
at require (internal/modules/cjs/helpers.js:16:16)
at Object. (/home/devteam11/TRD/new-rest-api/node_modules/configstore/index.js:5:17)
at Module._compile (internal/modules/cjs/loader.js:776:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:787:10)
`

Environment details
OS: Ubuntu 18.04
Node.js version: v10.16.0
npm version: 6.9.2
@google-cloud/storage version: 2.5.0
Steps to reproduce
package.json contains: "@google-cloud/storage": "2.5.0",

Thanks!

storage needs more info question

Most helpful comment

Ok next thing 馃槅 Can you rm -rf node_modules package-lock.json and then npm install again?

All 8 comments

@cstrd for "@google-cloud/storage": "2.5.0"
the syntax should be

const {Storage} = require('@google-cloud/storage');
const storage = new Storage();

If you still experience a problem, please refer to this answer.

Sorry to see you having trouble here again. Something is likely wrong with your installation or global env. Can you take this code, plop it in a file, and run it? In the same directory as the code you're trying? Then share the output?

console.log(process.version);
var gcs = require('@google-cloud/storage');
var cache = require.cache;
for (var prop in cache) {
  if (prop.indexOf('@google-cloud/storage/build/src/index.js') > 0) {
    console.log(cache[prop]);
  }
}

const pkg = require('./node_modules/@google-cloud/storage/package.json');
console.log(pkg.version);

It feels like the problem is somehow coming from make_dir module and the line it finally fails at is

node_modules/make_dir/index.js

const {promisify} = require('util');

What does node --version say, can you please copy and paste here?

@JustinBeckwith
Here is the output:

v8.6.0
/home/devteam11/TRD/new-rest-api/node_modules/pify/index.js:3
const processFn = (fn, opts) =
^^^^^^^^^^

ReferenceError: Invalid left-hand side in assignment
at createScript (vm.js:80:10)
at Object.runInThisContext (vm.js:139:10)
at Module._compile (module.js:588:28)
at Object.Module._extensions..js (module.js:635:10)
at Module.load (module.js:545:32)
at tryModuleLoad (module.js:508:12)
at Function.Module._load (module.js:500:3)
at Module.require (module.js:568:17)
at require (internal/module.js:11:18)
at Object. (/home/devteam11/TRD/new-rest-api/node_modules/make-dir/index.js:4:14)

@alexander-fenster v8.6.0

Ok next thing 馃槅 Can you rm -rf node_modules package-lock.json and then npm install again?

Yeah - your node_modules are corrupt :) Here's the problem. Your stack trace has this:

/home/devteam11/TRD/new-rest-api/node_modules/pify/index.js:3
const processFn = (fn, opts) =

That line is supposed to read:

const processFn = (fn, options) => function (...args) {

That means something went catawampus for you during npm install. The tip above should fix this.

@JustinBeckwith Thanks a lot! It got fixed...

Was this page helpful?
0 / 5 - 0 ratings