Node.js 云功能包部署错误
我正在使用sharp转换带有云函数的图像。Visual studio代码,类型脚本 我将其导入为:Node.js 云功能包部署错误,node.js,typescript,firebase,google-cloud-functions,sharp,Node.js,Typescript,Firebase,Google Cloud Functions,Sharp,我正在使用sharp转换带有云函数的图像。Visual studio代码,类型脚本 我将其导入为: import * as sharp from 'sharp'; 我是这样使用它的: export const generateThumbs = functions.storage .object() .onFinalize(async object => { const bucket = gcs.bucket(object.bucket); const f
import * as sharp from 'sharp';
我是这样使用它的:
export const generateThumbs = functions.storage
.object()
.onFinalize(async object => {
const bucket = gcs.bucket(object.bucket);
const filePath = object.name;
const fileName = filePath.split('/').pop();
const bucketDir = dirname(filePath);
const workingDir = join(tmpdir(), 'thumbs');
const tmpFilePath = join(workingDir, 'source.png');
if (fileName.includes('thumb@') || !object.contentType.includes('image')) {
console.log('exiting function');
return false;
}
// 1. Ensure thumbnail dir exists
await fs.ensureDir(workingDir);
// 2. Download Source File
await bucket.file(filePath).download({
destination: tmpFilePath
});
// 3. Resize the images and define an array of upload promises
const sizes = [64, 128, 256];
const uploadPromises = sizes.map(async size => {
const thumbName = `thumb@${size}_${fileName}`;
const thumbPath = join(workingDir, thumbName);
// Resize source image
await sharp(tmpFilePath)
.resize(size, size)
.toFile(thumbPath);
// Upload to GCS
return bucket.upload(thumbPath, {
destination: join(bucketDir, thumbName)
});
});
// 4. Run the upload operations
await Promise.all(uploadPromises);
// 5. Cleanup remove the tmp/thumbs from the filesystem
return fs.remove(workingDir);
});
(来自fireship.io的代码)
这是我的package.json文件
"dependencies": {
"@firebase/app": "^0.4.22",
"@firebase/app-types": "^0.4.7",
"@google-cloud/storage": "^4.1.0",
"@sendgrid/client": "^6.4.0",
"@sendgrid/contact-importer": "^6.4.0",
"@sendgrid/mail": "^6.4.0",
"@std/esm": "^0.26.0",
"@types/algoliasearch": "^3.34.5",
"@types/react": "^16.9.11",
"@types/react-dom": "^16.9.3",
"algolia-firebase-functions": "^3.2.0",
"algoliasearch": "^3.35.1",
"async.ensureasync": "^0.5.2",
"async.queue": "^0.5.2",
"bottleneck": "^2.19.5",
"debug": "^4.1.1",
"express": "^4.17.1",
"firebase": "^7.2.3",
"firebase-admin": "^8.7.0",
"firebase-functions": "^3.3.0",
"flag": "^4.4.0",
"fs-extra": "^8.1.0",
"geofirex": "0.0.6",
"images-downloader": "^1.0.3",
"lodash.chunk": "^4.2.0",
"react-redux": "^7.1.1",
"request": "^2.88.0",
"rxfire": "^3.8.8",
"rxjs": "^6.5.3",
"sharp": "^0.23.2",
"tmp": "^0.1.0"
},
因为我使用了sharp软件包,所以当我运行:firebase deploy--only functions:myFunctionName时,我得到了这个消息
There was an unknown problem while trying to parse function triggers. Please ensure you are using Node.js v6 or greater.
我正在使用节点12.3.1
谢谢你的帮助 请编辑问题,以更详细地显示CLI的输出,以及导致问题的整个最小代码。谢谢,我编辑了它,这是唯一的错误…你确定CLI输出没有比这一行更多的内容吗?是的,它真的很奇怪。。。这是CLI输出:✔ 功能:已完成运行predeploy脚本。i功能:确保启用必要的API。。。✔ 功能:所有必要的API都已启用i功能:准备要上载的功能目录。。。错误:尝试分析函数触发器时出现未知问题。请确保您使用的是Node.js v6或更高版本。我建议直接联系Firebase支持部门以获得故障排除帮助。