gpt4 book ai didi

node.js - 未找到模块 : Can't resolve 'fs' on @google-cloud/storage

转载 作者:行者123 更新时间:2023-12-04 13:55:03 25 4
gpt4 key购买 nike

获取 Module not found: Can't resolve 'fs'尝试从 GCP 存储中列出存储桶时出错。

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));
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
使用 googleapis 时出现同样的错误.
但是,而不是 ./node_modules/@google-cloud/storage/build/src/file.js:24:0它在 google-auth-library googleapis 附带的模块.
添加使用 yarn .

最佳答案

发帖 solution在评论中提供的可见性。

In your webpack configuration, you can indicate that certain moduleslike fs should be stubbed out; at which point you should be able torun this library client-side. For example:

node: {
// Some libraries import Node modules but don't use them in the browser.
// Tell Webpack to provide empty mocks for them so importing them works.
...config.node,
fs: 'empty',
child_process : 'empty',
net : 'empty',
tls: 'empty',
}

关于node.js - 未找到模块 : Can't resolve 'fs' on @google-cloud/storage,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64010488/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com