Because aws-cdk-lib v2 is esm only, the only way I was able to make Node-RED load it was using esbuild to bundle it together with my authored source code. Is there another option?
When I configure esbuild to avoid bundling aws-cdk-lib, esbuild uses require
with it and it doesn't work because it is an esm only module. Can Node-RED run an esm build? How can I do it?
I can't have an esm build because then I'm required to use "type": "module" in my custom node package.json because I get this runtime error
Node 18
23 May 19:01:11 - [warn] [node-red-custom-nodes/nodes] Error [ERR_REQUIRE_ESM]: require() of ES Module /Users/allanoricil/node-red-custom-nodes/dist/index.js from /Users/allanoricil/.nvm/versions/node/v18.18.0/lib/node_modules/node-red/node_modules/@node-red/registry/lib/loader.js not supported.
Node 22
23 May 19:03:17 - [warn] [node-red-custom-nodes/nodes] Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'aws-cdk-lib' imported from /Users/allanoricil/node-red-custom-nodes/dist/index.js
The above message for Node 22 is weird because I can see aws-cdk-lib
package in ~/.node-red/node_modules
The aws-cdk-lib
package is located in ~/.node-red
. Neither require
nor import
can find it at runtime. What could it be?