Comments (4)
In case it's useful, as I've been debugging related issues for my own setup, I took a rough pass at a patch to expose the reexports. This is not my area of expertise so I make no claims that this is the correct way of doing it, but it at least appears to work in my use case.
The following is what I applied (via patch-package - import-in-the-middle+1.4.1.patch
) - if it winds up being that this is actually reasonable, I'm happy to work on moving this into a PR. Minimally the way I'm dealing with path resolution here seems... wrong, though
diff --git a/node_modules/import-in-the-middle/lib/get-exports.js b/node_modules/import-in-the-middle/lib/get-exports.js
index cfa86d4..d93516a 100644
--- a/node_modules/import-in-the-middle/lib/get-exports.js
+++ b/node_modules/import-in-the-middle/lib/get-exports.js
@@ -3,12 +3,26 @@
const getEsmExports = require('./get-esm-exports.js')
const { parse: getCjsExports } = require('cjs-module-lexer')
const fs = require('fs')
-const { fileURLToPath } = require('url')
+const { fileURLToPath, pathToFileURL } = require('url')
function addDefault(arr) {
return Array.from(new Set(['default', ...arr]))
}
+async function getFullCjsExports(url, context, parentLoad, source) {
+ const ex = getCjsExports(source)
+ return Array.from(new Set([
+ ...addDefault(ex.exports),
+ ...(await Promise.all(ex.reexports.map(re => getExports(
+ re.startsWith('./') || re.startsWith('../')
+ ? pathToFileURL(require.resolve(fileURLToPath(new URL(re, url)))).toString()
+ : pathToFileURL(require.resolve(re)).toString(),
+ context,
+ parentLoad
+ )))).flat()
+ ]))
+}
+
async function getExports (url, context, parentLoad) {
// `parentLoad` gives us the possibility of getting the source
// from an upstream loader. This doesn't always work though,
@@ -33,7 +47,7 @@ async function getExports (url, context, parentLoad) {
return getEsmExports(source)
}
if (format === 'commonjs') {
- return addDefault(getCjsExports(source).exports)
+ return getFullCjsExports(url, context, parentLoad, source)
}
// At this point our `format` is either undefined or not known by us. Fall
@@ -44,7 +58,7 @@ async function getExports (url, context, parentLoad) {
// isn't set at first and yet we have an ESM module with no exports.
// I couldn't construct an example that would do this, so maybe it's
// impossible?
- return addDefault(getCjsExports(source).exports)
+ return getFullCjsExports(url, context, parentLoad, source)
}
}
from import-in-the-middle.
@luxaritas Yes, this seems like a great start. Can you move it to a draft PR, and add tests?
from import-in-the-middle.
Done - let me know if there's anything else I can do to help!
from import-in-the-middle.
this issue is still happening, is there any fix for it or workaround?
from import-in-the-middle.
Related Issues (20)
- Don't use parser for Node v22? HOT 4
- Use `es-module-lexer` to parse ESM
- Doesn't handle exports with invalid identifiers
- `getFullCjsExports` does not resolve re-exports from external dependencies
- IITM Throws Error When an NPM Package is Not Installed in the Root Folder HOT 7
- Are sequential patched supported? HOT 6
- parentResolve is not a function HOT 1
- Should fail gracefully when exports cannot be parsed
- Explicitly named exports should be exported over `export *` exports HOT 3
- Acorn parser does not support import attributes
- SyntaxError on importing some packages when using register() HOT 13
- SyntaxError when importing a JSON file using { type: 'json' } HOT 3
- import-in-the-middle' failed to wrap 'file:///app/node_modules/@prisma/client/default.js' HOT 2
- iitm wrappers copy exported primitives HOT 1
- Update LICENSE and NOTICE
- Codify governance HOT 2
- Resolve exports for native modules
- Errors when importing vue/server-renderer
- Import in the middle breaks `drizzle-orm` exports HOT 3
- Unable to import from Vue
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from import-in-the-middle.