I’m using Functions and trying to use the
@protobuf-ts/runtime npm module as a runtime dependency in my project. This runtime dependency works locally on my machine but when I deploy and then invoke my function I get greeted with
Error: Cannot find module '@protobuf-ts/runtime', with the code
MODULE_NOT_FOUND. I find this surprising as I installed this dependency the same way I installed another dependency,
@aws-sdk/client-s3, which works as expected at runtime.
In an attempt to isolate the issue I have…
doctl serverless init --language ts test-do-project-0.
npm install @protobuf-ts/runtimein the sample/hello function directory.
@protobuf-ts/runtimeand used it in the main function.
When I deploy and invoke the function it errors with:
2023-05-02T21:57:49.277554254Z stdout: ReferenceError: exports is not defined in ES module scope 2023-05-02T21:57:49.277556929Z stdout: at file:///tmp/index.mjs:2:23 2023-05-02T21:57:49.277577833Z stdout: at ModuleJob.run (node:internal/modules/esm/module_job:194:25)
I have tried fiddling with the
tsconfig.json module settings to resolve the issue to no avail, only succeeding in matching my original error (
Cannot find module '@protobuf-ts/runtime'). The function
package.json does not include
If I instead
npm install @aws-sdk/client-s3 and import and use it in
hello.ts instead of
@protobuf-ts/runtime, then everything works as expected. This makes me wonder if it is a problem specific to the
@protobuf-ts/runtime npm module, but since it works locally on my machine, it must be something to do with how this dependency is handled in the DO Function Node runtime. Perhaps there is a difference in npm version?
For reference and reproduction I have pushed the issue isolating Functions project to Github: https://github.com/willjvsmith/test-do-project-0
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.