async function _tryRequire(appRoot, moduleRoot, module) {
  verbose(
    "Try loading as commonjs: ",
    module,
    " with paths: ,",
    appRoot,
    moduleRoot,
  )

  const lambdaStylePath = path.resolve(appRoot, moduleRoot, module)

  // Extensionless files are loaded via require.
  const extensionless = _tryRequireFile(lambdaStylePath)
  if (extensionless) {
    return extensionless
  }

  // If package.json type != module, .js files are loaded via require.
  const pjHasModule = _hasPackageJsonTypeModule(lambdaStylePath)
  if (!pjHasModule) {
    const loaded = _tryRequireFile(lambdaStylePath, ".js")
    if (loaded) {
      return loaded
    }
  }

  // If still not loaded, try .js, .mjs, .cjs and .ts in that order.
  // Files ending with .js and .ts are loaded as ES modules when the nearest parent package.json
  // file contains a top-level field "type" with a value of "module".
  // https://nodejs.org/api/packages.html#packages_type
  const loaded =
    (pjHasModule && (await _tryAwaitImport(lambdaStylePath, ".js"))) ||
    (await _tryAwaitImport(lambdaStylePath, ".mjs")) ||
    _tryRequireFile(lambdaStylePath, ".cjs") ||
    (pjHasModule &&
      (await tsImport(`${lambdaStylePath}.ts`, `${lambdaStylePath}.ts`))) ||
    tsxRequire(`${lambdaStylePath}.ts`, `${lambdaStylePath}.ts`)
  if (loaded) {
    return loaded
  }

  verbose(
    "Try loading as commonjs: ",
    module,
    " with path(s): ",
    appRoot,
    moduleRoot,
  )

  // Why not just require(module)?
  // Because require() is relative to __dirname, not process.cwd(). And the
  // runtime implementation is not located in /var/task
  // This won't work (yet) for esModules as import.meta.resolve is still experimental
  // See: https://nodejs.org/api/esm.html#esm_import_meta_resolve_specifier_parent
  const nodeStylePath = require.resolve(module, {
    paths: [appRoot, moduleRoot],
  })

  return require(nodeStylePath)
}
Attempt to load the user's module.
Attempts to directly resolve the module relative to the application root,
then falls back to the more general require().