Search code examples
requiregcloudbucklescript

How to work with bucklescript requires and google functions


I'm trying to deploy functions created with bucklescript to google functions but the deploy won't run without this error :

Did you list all required modules in the package.json dependencies? Detailed stack trace: Error: Cannot find module 'bs-platform/lib/js/js_json.js'

I'm using the gcloud beta functions deploy utility. My code is using the Js.Json module, which produce var Js_json = require("bs-platform/lib/js/js_json.js"); in the outputed js code. My package.json contains the bs-platform package.

Is there a way to setup bucklescript or the gcloud utility to make my code acceptable?


Solution

  • BuckleScript's requires are just standard CommonJS requires, and can be bundled up into a single file using a bundler like webpack. You can also configure bsb to emit es6 modules (see the package-specs property of the bsconfig.json schema) and bundle them up using rollup.