0
votes

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)

2
What version of node are you using? And does your code need to be transpiled? This seems like it might be related to your environment not supporting arrow functions. (I'm assuming that's what comes after processFn = (fn, opts) = but it's cut off so I'm not sure.Khauri

2 Answers

0
votes

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.

0
votes

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.