@google-cloud/storage version: ^2.1.0I 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,
});
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?
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.
thanks!
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.. :/
@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!
import { Storage } from '@google-cloud/storage';
or
const { Storage } = require('@google-cloud/storage');
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();
Most helpful comment
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
We're sorry that this is causing problems on your end, we are working to get types working.