therightdoctors
therightdoctors

Reputation: 548

ReferenceError: Invalid left-hand side in assignment when importing @google-cloud/storage

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

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

When I comment the line, everything works fine. Below is the error I get:

/home/trd/TRD/new-rapi/copy/676cb539092d21127ded33478d1073ab6886fc33/node_modules/pify/index.js:3 const processFn = (fn, opts) = ^^^^^^^^^^

ReferenceError: Invalid left-hand side in assignment at new Script (vm.js:79:7) at createScript (vm.js:251:10) at Object.runInThisContext (vm.js:303:10) at Module._compile (internal/modules/cjs/loader.js:657:28) at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10) at Module.load (internal/modules/cjs/loader.js:599:32) at tryModuleLoad (internal/modules/cjs/loader.js:538:12) at Function.Module._load (internal/modules/cjs/loader.js:530:3) at Module.require (internal/modules/cjs/loader.js:637:17) at require (internal/modules/cjs/helpers.js:22:18) at Object. (/home/trd/TRD/new-rapi/copy/676cb539092d21127ded33478d1073ab6886fc33/node_modules/make-dir/index.js:4:14) at Module._compile (internal/modules/cjs/loader.js:689:30) at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10) at Module.load (internal/modules/cjs/loader.js:599:32) at tryModuleLoad (internal/modules/cjs/loader.js:538:12) at Function.Module._load (internal/modules/cjs/loader.js:530:3)

Upvotes: 0

Views: 801

Answers (2)

Jan Hernandez
Jan Hernandez

Reputation: 4640

You can try to import the library like this example

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

A full example is in github quick start example

If the problem continue, maybe is related with your local environment I would recommend you try to set a clean development env in a linux VM and using Node.JS 10, this is in order to discard that the issue is related with any bad configuration.

Upvotes: 0

Catar4
Catar4

Reputation: 208

You are declaring a constant while importing.

I recommend you should use

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

Replace "const" by "let" or "var". It should help.

Upvotes: 0

Related Questions