首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >导入@google云/存储时出错。

导入@google云/存储时出错。
EN

Stack Overflow用户
提问于 2020-12-13 21:20:52
回答 1查看 1.3K关注 0票数 2

导入@google云/存储后,我就出错了。

环境细节

  • 操作系统: macOS大Sur
  • Node.js版本: v12.18.4
  • 国家预防机制版本:6.14.6
  • @google-云/存储版本:^ 5.6.0
  • framework版本: Nuxt.js @ v2.14.7

复制的步骤

  • 安装@google-云/存储 添加@google云/存储或npm安装@google云/存储-保存

进口它

代码语言:javascript
复制
const {Storage} = require('@google-cloud/storage');
const storage = new Storage({
keyFilename : path.join(__dirname, './file.json'),
projectId: "xxx-xxx-xxx"
});

就在那之后我得到了这个错误

ERROR in ./node_modules/google-auth-library/build/src/auth/googleauth.js Module not found: Error: Can't resolve 'child_process' in '/Users/xxx/xxxx/node_modules/google-auth-library/build/src/auth' ERROR in ./node_modules/@google-cloud/storage/build/src/file.js Module not found: Error: Can't resolve 'fs' in '/Users/xxx/xxxx/node_modules/@google-cloud/storage/build/src' ERROR in ./node_modules/@google-cloud/storage/build/src/bucket.js Module not found: Error: Can't resolve 'fs' in '/Users/xxx/xxxx/node_modules/@google-cloud/storage/build/src' ERROR in ./node_modules/configstore/node_modules/make-dir/index.js Module not found: Error: Can't resolve 'fs' in '/Users/xxx/xxxx/node_modules/configstore/node_modules/make-dir' ERROR in ./node_modules/google-auth-library/build/src/auth/googleauth.js Module not found: Error: Can't resolve 'fs' in '/Users/xxx/xxxx/node_modules/google-auth-library/build/src/auth' ERROR in ./node_modules/google-p12-pem/build/src/index.js Module not found: Error: Can't resolve 'fs' in '/Users/xxx/xxxx/node_modules/google-p12-pem/build/src' ERROR in ./node_modules/graceful-fs/graceful-fs.js Module not found: Error: Can't resolve 'fs' in '/Users/xxx/xxxx/node_modules/graceful-fs' ERROR in ./node_modules/gtoken/build/src/index.js Module not found: Error: Can't resolve 'fs' in '/Users/xxx/xxxx/node_modules/gtoken/build/src' ERROR in ./node_modules/write-file-atomic/index.js Module not found: Error: Can't resolve 'fs' in '/Users/xxx/xxxx/node_modules/write-file-atomic' ERROR in ./node_modules/http-proxy-agent/dist/agent.js Module not found: Error: Can't resolve 'net' in '/Users/xxx/xxxx/node_modules/http-proxy-agent/dist' ERROR in ./node_modules/https-proxy-agent/dist/agent.js Module not found: Error: Can't resolve 'net' in '/Users/xxx/xxxx/node_modules/https-proxy-agent/dist' ERROR in ./node_modules/http-proxy-agent/dist/agent.js Module not found: Error: Can't resolve 'tls' in '/Users/xxx/xxxx/node_modules/http-proxy-agent/dist' ERROR in ./node_modules/https-proxy-agent/dist/agent.js Module not found: Error: Can't resolve 'tls' in '/Users/xxx/xxxx/node_modules/https-proxy-agent/dist

我试图重写webpack配置,添加

代码语言:javascript
复制
 config.node : {
        fs: 'empty', 
        net: 'empty', 
        tls: 'empty', 
        child_process: 'empty', 
        __filename: true, 
        __dirname: true
     }

这是我找到的唯一解决办法,但我还是会犯错误

代码语言:javascript
复制
TypeError: The "original" argument must be of type Function
    at promisify (util.js?3022:602)
    at eval (index.js?5051:7)
    at Object../node_modules/@google-cloud/storage/node_modules/get-stream/index.js (index.js:275)
    at __webpack_require__ (runtime.js:854)
    at fn (runtime.js:151)
    at Object.eval (file.js?5fe9:20)
    at eval (file.js:3042)
    at Object../node_modules/@google-cloud/storage/build/src/file.js (index.js:167)
    at __webpack_require__ (runtime.js:854)
    at fn (runtime.js:151)
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-12-16 11:41:50

您在客户端代码上使用@google/存储的问题是,这个库应该在仅服务器端上使用。

记住,Nuxt是一个SSR(服务器端呈现),即使它在服务器上呈现,很多代码也会出现在客户端。您可以尝试在服务器端组件(如serverMiddleware属性 )上使用此方法。

要在客户端运行存储,请尝试使用npm火场储存

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/65280808

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档