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

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

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

I have tried importing using:

  1. const {Storage} = require(‘@google-cloud/storage’); const storage = new Storage();
  2. let gcs = require(‘@google-cloud/storage’); But I get the same error. 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)

When I try to import it as: import * as Storage from ‘@google-cloud/storage’; ^ I get Syntax error:

SyntaxError: Unexpected token *
    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.<anonymous> (/home/trd/TRD/new-rapi/676cb539092d21127ded33478d1073ab6886fc33/server.js:41:15)
    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)

Environment details

  • OS: Ubuntu 19.04
  • Node.js version: 10.15.2
  • npm version: 6.9.0
  • @google-cloud/storage version:

Steps to reproduce

  1. package.json contains: “@google-cloud/storage”: “^1.7.0”,

Making sure to follow these steps will guarantee the quickest resolution possible.

Thanks!

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 24 (12 by maintainers)

Most upvoted comments

@JustinBeckwith Thanks a ton! It worked!!