Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
timfish opened this issue Jun 4, 2024 · 0 comments · Fixed by #96
Closed

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

timfish opened this issue Jun 4, 2024 · 0 comments · Fixed by #96

Comments

@timfish
Copy link
Contributor

timfish commented Jun 4, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant