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

parentResolve is not a function #99

Closed
gajus opened this issue Jun 11, 2024 · 1 comment · Fixed by #100
Closed

parentResolve is not a function #99

gajus opened this issue Jun 11, 2024 · 1 comment · Fixed by #100

Comments

@gajus
Copy link

gajus commented Jun 11, 2024

Expected Behavior

import-in-the-middle to work.

Actual Behavior

at 20:24:19 ❯ node --import @sentry/node/preload ./dist/bin/server.js

node:internal/modules/run_main:125
    triggerUncaughtException(
    ^
TypeError [Error]: parentResolve is not a function
    at processModule (/Users/x/Developer/contra/gaia/node_modules/.pnpm/import-in-the-middle@1.8.0/node_modules/import-in-the-middle/hook.js:154:30)
    at async processModule (/Users/x/Developer/contra/gaia/node_modules/.pnpm/import-in-the-middle@1.8.0/node_modules/import-in-the-middle/hook.js:160:23)

This is the line where it happens:

        // Bare specifiers need to be resolved relative to the parent module.
        const result = await parentResolve(modFile, { parentURL: srcUrl })

If I inject console.log({parentResolve, modFile}); before, it prints:

{
  parentResolve: [AsyncFunction: nextResolve],
  modFile: '@envelop/types'
}
{
  parentResolve: [AsyncFunction: nextResolve],
  modFile: '@graphql-yoga/logger'
}

Appears to be some sort of race condition.

async function processModule ({ srcUrl, context, parentGetSource, parentResolve, excludeDefault }) {
+  console.log({parentResolve});

  const exportNames = await getExports(srcUrl, context, parentGetSource)
  const duplicates = new Set()
  const setters = new Map()

  const addSetter = (name, setter) => {
    // When doing an `import *` duplicates become undefined, so do the same
    if (setters.has(name)) {
      duplicates.add(name)
      setters.delete(name)
    } else if (!duplicates.has(name)) {
      setters.set(name, setter)
    }
  }

  for (const n of exportNames) {
    if (n === 'default' && excludeDefault) continue

    if (isStarExportLine(n) === true) {
      const [, modFile] = n.split('* from ')

      let modUrl
      if (isBareSpecifier(modFile)) {
+        console.log({parentResolve, modFile});

        // Bare specifiers need to be resolved relative to the parent module.
        const result = await parentResolve(modFile, { parentURL: srcUrl })
{ parentResolve: [AsyncFunction: nextResolve] }
{ cachedResolve: [AsyncFunction: nextResolve] }
{ parentResolve: [AsyncFunction: nextResolve] }
{ parentResolve: undefined }
{
  parentResolve: [AsyncFunction: nextResolve],
  modFile: '@envelop/types'
}
{ parentResolve: undefined }

Steps to Reproduce the Problem

N/A

Specifications

  • Version: v22.1.0
  • Platform: macOS
  • Subsystem: N/A
@gajus
Copy link
Author

gajus commented Jun 11, 2024

Actually, this invocation is coming from:

const setters = await processModule({
  srcUrl: modUrl,
  context,
  parentGetSource,
  excludeDefault: true
})

parentResolve is not passed here, so it is indeed undefined.

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