Cannot find module 'rimraf'

The Deployment is OK, using netlify CLI to test functions works, but the moment the function is live it just keeps giving the same error.

Nov 19, 03:00:25 AM: b88bb1a6 ERROR  2024-11-19T03:00:25.792Z	undefined	ERROR	Uncaught Exception 	{"errorType":"Runtime.ImportModuleError","errorMessage":"Error: Cannot find module 'rimraf'\nRequire stack:\n- /var/task/update-inventory.mjs","stack":["Runtime.ImportModuleError: Error: Cannot find module 'rimraf'","Require stack:","- /var/task/update-inventory.mjs","    at _loadUserApp (file:///var/runtime/index.mjs:1087:17)","    at async UserFunction.js.module.exports.load (file:///var/runtime/index.mjs:1119:21)","    at async start (file:///var/runtime/index.mjs:1282:23)","    at async file:///var/runtime/index.mjs:1288:1"]}
Nov 19, 03:00:25 AM: b88bb1a6 ERROR  INIT_REPORT Init Duration: 433.04 ms	Phase: invoke	Status: error	Error Type: Runtime.ImportModuleError
Nov 19, 03:00:25 AM: b88bb1a6 ERROR  Unknown application error occurred
Nov 19, 03:00:25 AM: b88bb1a6 ERROR  Runtime.ImportModuleError

Tried with and without this netlify configuration:

[functions]
  node_bundler = "esbuild"
  external_node_modules = ["fs", "rimraf", "axios", "xml2js"]

To this point most of what i tried won’t work.
What am I missing in the configuration, can I even use rimraf?
The code inside this function imports a function from a .js source file in the root of the project
like this:

import { UpInventory } from "../../updateinventory"

Functions are inside a folder ‘netlify/functions’

Thanks in advance

While it might be worth debugging the rimraf missing issue, the real problem you’d have even if you get it working is that, rimraf would likely not work. AWS Lambda containers don’t allow you to write data. Since deletion is considered as writing, it would likely not work.

During the Build Process we run this function that removes and creates a bunch of .json files.
It actually works, we just don’t want to deploy the app multiple times a week.

And we thought “Why don’t we use Netlify functions to run this every day”.
We can actually deploy the app every week to update these files.

We will try and debug even further, the problem is that rimraf is not being recognised in the functions.

You cannot use Functions to delete files from a deploy.