[Bug]: "Cannot find module" when dynamic importing in CJS file
Closed this issue · 2 comments
Data Provider
Blockfrost
DEX
All
Description
Attempting to dynamically load the Dexter module inside a .js or .cjs file results in the following error:
Error [ERR_MODULE_NOT_FOUND]: Cannot find module 'E:\Data\Dev\project\discord\node_modules\@indigo-labs\dexter\build\constants' imported from E:\Data\Dev\project\discord\node_modules\@indigo-labs\dexter\build\index.js
I believe this is because all files imported within Dexter don't include their filetypes in their import paths. I'd like to avoid having to convert my entire existing project to TS, so if there's a workaround to get this going on plain JS that'd be great.
Code to repro:
await import("@indigo-labs/dexter")
.then((DexterLib) => {
//...
})
Platform: Windows
Node version: v18.13.0
Just an update on this;
I made a start on porting my project to TS but am encountering the same error (the same issue Nick was facing here: #58). I can get it to build by setting the following compilerOptions
in my tsconfig
, but this causes build issues with other files:
"module": "Node16",
"skipLibCheck": true,
"moduleResolution": "Node"
I've managed to temporarily resolve this by using the --experimental-specifier-resolution=node
flag when executing node.