【问题标题】:Cannot find module '@google-cloud/storage'找不到模块“@google-cloud/storage”
【发布时间】:2018-06-01 21:07:41
【问题描述】:

我在浏览器上使用 GCP 控制台。我创建了如下函数:

function listFiles(bucketName) {
  // [START storage_list_files]
  // Imports the Google Cloud client library
  const Storage = require('@google-cloud/storage');

  // Creates a client
  const storage = new Storage();


  storage
.bucket(bucketName)
.getFiles()
.then(results => {
  const files = results[0];

  console.log('Files:');
  files.forEach(file => {
    console.log(file.name);
  });
})
.catch(err => {
  console.error('ERROR:', err);
    });
  // [END storage_list_files]
}

exports.helloWorld = function helloWorld (req, res) {
  if (req.body.message === undefined) {
    // This is an error case, as "message" is required
    res.status(400).send('No message defined!');
  } 
  else {
    // Everything is ok
    console.log(req.body.lat);
    console.log(req.body.lon);
    listFiles("drive-test-demo");
    res.status(200).end();
  }
}

实际上,我现在要做的就是列出存储桶中的文件,如果某个 HTTPS 触发器通过。

我的 package.json 文件如下:

{
  "name": "sample-http",
  "version": "0.0.1",
  "dependencies": {
    "@google-cloud/storage": "1.5.1"
  }

} 

我收到错误“找不到模块'@google-cloud/storage'”

到目前为止,我看到的大多数查询都已通过使用 npm install 解决,但考虑到我的 index.js 和 package.json 文件存储在 gcloud 存储桶内的 zip 文件中,我不知道该怎么做。任何关于如何解决这个问题的建议都会非常感激。

【问题讨论】:

  • 你应该安装 npm 并运行 npm install

标签: google-cloud-platform google-cloud-functions


【解决方案1】:

打开控制台,将目录更改为您的函数项目并输入:

npm install --save @google-cloud/storage

就是这样!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-01-08
    • 2023-03-05
    • 1970-01-01
    • 2018-06-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多