Giter VIP home page Giter VIP logo

Comments (1)

dawnmist avatar dawnmist commented on August 17, 2024

I've made some attempt to debug what is going on, though it's only been partially successful.

Replacing line: https://github.com/DataDog/import-in-the-middle/blob/c3c2c52c1915b47994af59d507c59029c1f1fae9/hook.js#L157

With:

      const isNodeModule = !(modFile.startsWith('.') || modFile.startsWith('/') || modFile.startsWith('file:'))
      const modUrl = isNodeModule
        ? new URL(require.resolve(modFile, {
          paths: [new URL(srcUrl).pathname]
        }), srcUrl).toString() 
        : new URL(modFile, srcUrl).toString()

This allows import-in-the-middle to get the correct url for submodule/child node_module library imports, however there is still an issue in that when it is processing those submodules import-in-the-middle fails to retrieve the submodule's exports. This results in the parent module being unable to re-export the submodule's exports as it does not know about the items being exported (the setters map for the submodule is returned as empty). The submodule then gets processed a second time after the parent has completed all its processing, this time properly picking up its own exports but it's too late at that point for the parent module to be informed of the child's exports. This then means that node throws errors that the parent "does not provide an export named 'XXX'" when it was one of the exports that the parent module was re-exporting from the submodule.

In terms of the isNodeModule test, I'm not sure if there are any other modFile exports likely to be seen, e.g. http: or deno:. If there are others that need to be treated like file/relative/absolute urls instead of using node resolution, that parameter should be updated to look for those too.

from import-in-the-middle.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.