找不到模块:无法解析 @google-cloud/storage 上的“fs”

mys*_*dad 7 node.js npm google-cloud-storage google-cloud-platform google-apis-explorer

Module not found: Can't resolve 'fs'尝试从 GCP Storage 列出存储桶时出现错误。

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

const googleCloud = new Storage({
  keyFilename: '../../my-project-c1a44bf80be3.json',
  projectId: 'my-project',
});

googleCloud.getBuckets().then((x: any) => console.log(x));
Run Code Online (Sandbox Code Playgroud)

my-project-c1a44bf80be3.json(从GCP下载)存在并且是项目级别

错误:

event - compiled successfully
event - build page: /
wait  - compiling...
error - ./node_modules/@google-cloud/storage/build/src/file.js:24:0
Module not found: Can't resolve 'fs'
null
Could not find files for / in .next/build-manifest.json
event - compiled successfully
Run Code Online (Sandbox Code Playgroud)

使用googleapis时会出现相同的错误。但是,./node_modules/@google-cloud/storage/build/src/file.js:24:0它不是google-auth-librarygoogleapis.

添加使用yarn.

Mad*_*eka 5

当您在客户端导入或引用 firebase-admin 时,通常会发生这种情况,请检查您的代码是否有可能调用的错误导入

import * as firebase from "firebase-admin";
Run Code Online (Sandbox Code Playgroud)

代替

import firebase from "firebase";
Run Code Online (Sandbox Code Playgroud)


小智 -5

您所描述的场景现在正在由 Google 处理。尽管没有预计到达时间,但该问题正在优先处理。