Trigger Function External Dependency not found

I am trying to have a simple js trigger use and external npm module

The module has this bit of js in it

exports.printMsg = function() {
  console.log("This is a message from the demo package");
 exports.myDateTime = function () {
	console.log("hello from myDateTime");
  return Date();

Using a basic package.json

  "name": "first_mongo_module",
  "version": "1.0.1",
  "description": "my first try",
  "main": "myFirstModule.js",
  "scripts": {
  "test": "echo \"Error: no test specified\" && exit 1"
  "author": "",
  "license": "ISC",
  "keywords": [], 
  "dependencies": {   
  "first_mongo_module": "^1.0.1" 

I ran the npm tools to create and then publish the package for public access

Used the GUI to import the dependency successfully and it show the newest version.

Inside the trigger
I have this simple js

exports = function(changeEvent) {
       const msg = require('first_mongo_module');

When the trigger fires I get an Error: Cannot find module ‘first_mongo_module’

Something simple must be missing.

BTW running this on a free tier on Azure, and the same simple module works using node.

Thanks in advance for any help or pointers.

1 Like

It works for me with this simple package.json:

{"version": "1.0.0","name":"my_package","main": "myCustomCode.js"}

And then the structure of the folder that I gzip:

  • node_modules
    • my_package
      • package.json
      • myCustomCode.js

And here’s my trigger function:

exports = function() {
  const { myFunc } = require("my_package/myCustomCode.js");
  return myFunc();

Thank you so much Florian.

I tried many variations with no success, and stopped trying to use the NPM public library and using the basic as you provided.

When I upload the gzip the page refreshes without errors or the dependancy listed, but have this message

Some Node standard libraries are not supported yet, packages relying on these libraries may not work as expected. Learn more about supported libraries.

It seems this is even more basic. I even use your exact package.json

Went back to square 1 one more time and finally got it to work and seems repeatable but only as the directory import.
Not clear what the error was, and will post here if it ever emerges.

Will get the open. NPM library working later.

Thanks again