Functions:Packages - bettyblocks/cli GitHub Wiki
Using packages with Functions works the same way as it does in a regular yarn
project.
You can simply add them with yarn and then use them in your function files as normal.
You can then import the package as you would in the index.js
of your function.
To add a package, simply yarn add <package>
to add it to your package.json.
Example:
$ yarn add fs-extra
// cli-wiki/package.json
{
"name": "cli-wiki",
"version": "1.0.0",
"dependencies": {
"lodash": "^4.17.21"
},
"private": "true"
}
Example:
// cli-wiki/functions/say-hello/1.0/index.js
import join from 'lodash/join';
const sayHello = async ({ name }) => {
return {as: join(['Hello', name], ', ')}
}
export default sayHello;
Due to the nature in which Functions are compiled and executed, it may not be possible to use a desired package because of the functionality it uses. For example, packages relying on fs will not install or may not function correctly. We currently do not have a defined list of packages that are not supported.
Also, any package that uses require
is currently not supported.
Trying to use such a package may result in a require is not defined
error.