Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't import Storage from @google-cloud/storage #456

Closed
Steven4294 opened this issue Oct 16, 2018 · 8 comments
Closed

Can't import Storage from @google-cloud/storage #456

Steven4294 opened this issue Oct 16, 2018 · 8 comments
Assignees
Labels
api: storage Issues related to the googleapis/nodejs-storage API. 🚨 This issue needs some love. triage me I really want to be triaged.

Comments

@Steven4294
Copy link

Environment details

  • Node.js version: 8.9.0
  • npm version: 5.5.1
  • @google-cloud/storage version: ^2.1.0

Steps to reproduce

I am just trying to setup GCS in a cloud code function. I am using typescript. However when I try to import { Storage } from '@google-cloud/storage'; i get an error that node_modules/@types/google-cloud__storage/index"' has no exported member 'Storage'.

If i try, import * as Storage from '@google-cloud/storage'; I get an error TypeError: Storage is not a constructor. Here is my dependency file and then my index.js.

   // in package.json
  "dependencies": {
    "@google-cloud/storage": "^2.1.0",
    "@types/google-cloud__storage": "^1.7.2",
    "firebase-admin": "~6.0.0",
    "firebase-functions": "^2.0.3",
    "fs-extra": "^7.0.0",
    "sharp": "^0.21.0"
  }

  // index.ts

import * as functions from 'firebase-functions';
import * as Storage from '@google-cloud/storage';

const projectId = 'xxxx';

const storage = new Storage({
 projectId: projectId,
});


@Steven4294
Copy link
Author

Steven4294 commented Oct 16, 2018

It seems that the correct way to import it is

import * as Storage from '@google-cloud/storage'

However, i'm getting the error that Storage is not a constructor. Am i missing something very obvious here?

@jkwlui
Copy link
Member

jkwlui commented Oct 16, 2018

Hi 👋 Thanks for filing an issue with us.

We've temporarily disabled types on nodejs-storage because we currently have some incomplete types and it was causing issues to people that uses TypeScript. That's why the import { Storage } from '@google-cloud/storage'; doesn't work currently.

For now, please use

import * as storage from '@google-cloud/storage';

const client = new storage.Storage();

We're sorry that this is causing problems on your end, we are working to get types working.

@jkwlui jkwlui closed this as completed Oct 16, 2018
@Steven4294
Copy link
Author

thanks!

@mpmckenz
Copy link

import * as storage from "@google-cloud/storage";
Gets an error as well:
SyntaxError: Unexpected token *

Looks like google cloud storage doesn't work at all right now. That's not very reliable.. :/

@JustinBeckwith
Copy link
Contributor

@mpmckenz are you writing TypeScript or JavaScript? For TypeScript that makes sense, for plain ol' JavaScript it would still just be const {Storage} = require('@google-cloud/storage');. Hope this helps!

@google-cloud-label-sync google-cloud-label-sync bot added the api: storage Issues related to the googleapis/nodejs-storage API. label Jan 31, 2020
@reduardo7
Copy link

import { Storage } from '@google-cloud/storage';

or

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

@yoshi-automation yoshi-automation added triage me I really want to be triaged. 🚨 This issue needs some love. labels Apr 6, 2020
@mahsanamin
Copy link

Unfortunately, In Node 12 the above snippets did not work in the module approach, so use below!

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

@JuanjoFR
Copy link

JuanjoFR commented Feb 4, 2022

In my case (Node 14) I needed something like this:

import * as storageModule from "@google-cloud/storage";
const { Storage } = storageModule;
const storage = new Storage();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: storage Issues related to the googleapis/nodejs-storage API. 🚨 This issue needs some love. triage me I really want to be triaged.
Projects
None yet
Development

No branches or pull requests

8 participants