【发布时间】:2020-06-03 05:25:26
【问题描述】:
我收到此错误Module name "@google-cloud/vision" has not been loaded yet for context: _. Use require([]),当我运行我的项目时,我在我的项目中包含了 require.js 以及我的 html 文件中的脚本标签<script data-main = "./app.js" src = "./libs/require.js"></script>,我浏览了许多关于 require.js 的文章,但无法'不明白它的实际用途是什么以及如何解决这个错误。
我也在 StackOverFlow 上浏览过这个帖子,但无法理解 Dynamic require in RequireJS, getting "Module name has not been loaded yet for context" error?
这是我的代码
///////////////////////////////////////////////////////////////
//UPLOAD IMAGE to cloud bucket
function showResults(){
const bucketName = //name-of-bucket;
const filename = './img2.jpg';
// Imports the Google Cloud client library
const {Storage} = require('@google-cloud/storage');
// Creates a client
const storage = new Storage();
async function uploadFile() {
// Uploads a local file to the bucket
await storage.bucket(bucketName).upload(filename, {
// Support for HTTP requests made with `Accept-Encoding: gzip`
gzip: true,
// By setting the option `destination`, you can change the name of the
// object you are uploading to a bucket.
metadata: {
// Enable long-lived HTTP caching headers
// Use only if the contents of the file will never change
// (If the contents will change, use cacheControl: 'no-cache')
cacheControl: 'public, max-age=31536000',
},
});
console.log(`${filename} uploaded to ${bucketName}.`);
}
uploadFile().catch(console.error);
}
///////////////////////////////////////////////////////////////////
【问题讨论】:
标签: javascript html google-chrome requirejs