Skip to content

getFullCjsExports does not resolve re-exports from external dependencies #95

@timfish

Description

@timfish

This had been fixed for ESM but not for CJS.

The following code should result in a default export
test.cjs

module.exports = require('util').deprecate;

Instead it results in the following error:

node:internal/process/esm_loader:40
      internalBinding('errors').triggerUncaughtException(
                                ^
Error: ENOENT: no such file or directory, open '/Users/tim/Documents/Repositories/import-in-the-middle/test/check-exports/util'
    at Object.readFileUtf8 (node:internal/fs/sync:25:18)
    at Object.readFileSync (node:fs:441:19)
    at getExports (/Users/tim/Documents/Repositories/import-in-the-middle/lib/get-exports.js:69:17)
    at async Promise.all (index 0)
    at async getFullCjsExports (/Users/tim/Documents/Repositories/import-in-the-middle/lib/get-exports.js:23:9)
    at async processModule (/Users/tim/Documents/Repositories/import-in-the-middle/hook.js:131:23)
    at async getSource (/Users/tim/Documents/Repositories/import-in-the-middle/hook.js:249:23)
    at async load (/Users/tim/Documents/Repositories/import-in-the-middle/hook.js:280:26)
    at async nextLoad (node:internal/modules/esm/hooks:833:22)
    at async Hooks.load (node:internal/modules/esm/hooks:416:20) {
  errno: -2,
  code: 'ENOENT',
  syscall: 'open',
  path: '/Users/tim/Documents/Repositories/import-in-the-middle/test/check-exports/util'
}

I think this is due to this code which doesn't support resolving bare specifiers or node built-ins?
https://github.com/DataDog/import-in-the-middle/blob/a8da141be1e0fe802cea9bdb83d39a61c3aea7f7/lib/get-exports.js#L20-L30

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions