Error: "Cannot Find Module 'tedious@1.11.0' Require Stack:..."

Problem statement

After having created a custom database and a login action script using the template for SQL Server, an error occurs in the Dashboard when attempting to test the script:

"Cannot Find Module ‘tedious@1.11.0’ Require Stack: - /data/io/node18/*******/webtask.is".

Cause

The custom database script templates in the documentation were created some time ago, and while they provide an example of each type of script, they may not be completely drop-in-ready-for-production.

To check the latest version of tedious that’s available for a tenant’s configured Node version, go to CanIRequire Can I require? - Search which node modules you can use in webtask.io, select the Node version, and see the available version of tedious. The example script is utilizing version 1.11.0, and the error stack trace will appear to point heavily at this library.

Solution

Update the login script to utilize a more modern version of each NPM package that is imported and reference each package’s documentation to confirm it’s up-to-date.

The Realtime Webtask Logs extension can also be used to view console.log statements placed in any of a tenant’s extensibility points, including custom database scripts. This can be a very useful tool in debugging and troubleshooting custom database scripts.