Bisonai/orakl

module resolution issue in cli workspace

Closed this issue · 0 comments

We use tsc to compile ts files into js in the cli workspace. As of this moment, typescript doesn't automatically add .js extensions during compilation. In order to avoid node complaining about relative imports not having the .js extension, we are currently adding the following --import=specifier-resolution-node/register flag when we run node dist/index.js. However, we are not adding that flag when we call the cli executable (from bin).

Therefore, when we install the cli globally and call the cli executable with npx @bisonai/orakl-cli, we run into the following error:

node:internal/modules/esm/resolve:265
    throw new ERR_MODULE_NOT_FOUND(
          ^

Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/Users/intizarbisonai/.nvm/versions/node/v20.12.2/lib/node_modules/@bisonai/orakl-cli/dist/adapter' imported from /Users/intizarbisonai/.nvm/versions/node/v20.12.2/lib/node_modules/@bisonai/orakl-cli/dist/index.js
    at finalizeResolution (node:internal/modules/esm/resolve:265:11)
    at moduleResolve (node:internal/modules/esm/resolve:933:10)
    at defaultResolve (node:internal/modules/esm/resolve:1157:11)
    at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:390:12)
    at ModuleLoader.resolve (node:internal/modules/esm/loader:359:25)
    at ModuleLoader.getModuleJob (node:internal/modules/esm/loader:234:38)
    at ModuleWrap.<anonymous> (node:internal/modules/esm/module_job:87:39)
    at link (node:internal/modules/esm/module_job:86:36) {
  code: 'ERR_MODULE_NOT_FOUND',
  url: 'file:///Users/intizarbisonai/.nvm/versions/node/v20.12.2/lib/node_modules/@bisonai/orakl-cli/dist/adapter'
}

Note: adding flags in the executable is not supported. We either need to:

  • add .js extensions during compilation (maybe using a bundler like webpack)
  • add .js extensions manually to all ts files
  • write a workaround sh or js script that will run the cli with flags