Skip to content

Instantly share code, notes, and snippets.

@prescottprue
Last active November 14, 2024 01:34
Show Gist options
  • Save prescottprue/b77e59c85941d2e93766e9055819da99 to your computer and use it in GitHub Desktop.
Save prescottprue/b77e59c85941d2e93766e9055819da99 to your computer and use it in GitHub Desktop.
Google Cloud Storage ESM/CJS Type Mismatch
import type { Storage, File } from '@google-cloud/storage' with { "resolution-mode": "import" }
async function someFunc(): Promise<File> {
const { Storage } = await import('@google-cloud/storage')
const storage = new Storage() // <- is ESM types, not CSJ
return storage.bucket(bucket).file(filePath) // not the same as File type
}
import type { Storage, File } from '@google-cloud/storage' // causes CJS types to be imported
async function someFunc(): Promise<File> {
const { Storage } = await import('@google-cloud/storage', { with: { "resolution-mode": "require" } })
const storage = new Storage() // <- is ESM types, not CSJ
return storage.bucket(bucket).file(filePath) // not the same as File type
}
import type { Storage, File } from '@google-cloud/storage' // causes CJS types to be imported
async function someFunc(): Promise<File> {
const { Storage } = await import('@google-cloud/storage')
const storage = new Storage() // <- is ESM types, not CSJ
return storage.bucket(bucket).file(filePath) // not the same as File type
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment