firebase / firebase/functions-samples
TypeError in ffmpeg-convert-audio example post updating @google-cloud/storage
- Dominant language
- JavaScript
- Stars
- 12.2k
- Forks
- 3.8k
- Avg merge
- 3d 23h
- Merged PRs (30d)
- 1
Description
Hi,
I was getting a TypeError in ffmpeg-convert-audio. Error output is below:
------
TypeError: require(...) is not a function
at Object. (/Users/aaabkumar/devel/apis/s2t/test-fb-func-js/functions/index.js:2:45)
at Module._compile (module.js:653:30)
at Object.Module._extensions..js (module.js:664:10)
at Module.load (module.js:566:32)
at tryModuleLoad (module.js:506:12)
at Function.Module._load (module.js:498:3)
at Module.require (module.js:597:17)
at require (internal/module.js:11:18)
at /usr/local/lib/node_modules/firebase-tools/lib/triggerParser.js:21:11
at Object. (/usr/local/lib/node_modules/firebase-tools/lib/triggerParser.js:75:3)
------
After little bit of digging, I figured that it seems to be the issue with the way @google-cloud/storage was being imported. I suppose the right code should be:
````javascript
const gcs = require('@google-cloud/storage');
````
and not as it is currently on the Node-8 branch:
````javascript
const gcs = require('@google-cloud/storage')();
````
My package.json file is below for the version reference:
````json
{
"name": "functions",
"description": "Cloud Functions for Firebase",
"scripts": {
"serve": "firebase serve --only functions",
"shell": "firebase functions:shell",
"start": "npm run shell",
"deploy": "firebase deploy --only functions",
"logs": "firebase functions:log"
},
"dependencies": {
"@google-cloud/storage": "^2.0.3",
"ffmpeg-static": "^2.3.0",
"firebase-admin": "~6.0.0",
"firebase-functions": "^2.0.3",
"fluent-ffmpeg": "^2.1.2"
},
"engines": {
"node": "8"
},
"private": true
}
````
Once, the import statement is corrected, line 55 which gets a reference of the storage bucket also should to be corrected to below code:
````javascript
const bucket = new gcs.Storage().bucket(fileBucket);
````
This fixed the issue and I was able to successfully deploy the function with firebase deploy.
Let me know if this all makes sense.
Thanks.
Contributor guide
Assessment
This issue has not been assessed yet.