% node --experimental-loader=import-in-the-middle/hook.mjs foo.mjs
(node:96950) ExperimentalWarning: Custom ESM Loaders is an experimental feature and might change at any time
(Use `node --trace-warnings ...` to show where the warning was created)
XXX IITM getCjsExports of url file:///Users/trentm/tmp/iitm-node20-exports/node_modules/@aws-sdk/client-s3/dist-cjs/index.js
-- source --
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.S3ServiceException = void 0;
const tslib_1 = require("tslib");
tslib_1.__exportStar(require("./S3Client"), exports);
tslib_1.__exportStar(require("./S3"), exports);
tslib_1.__exportStar(require("./commands"), exports);
tslib_1.__exportStar(require("./pagination"), exports);
tslib_1.__exportStar(require("./waiters"), exports);
tslib_1.__exportStar(require("./models"), exports);
var S3ServiceException_1 = require("./models/S3ServiceException");
Object.defineProperty(exports, "S3ServiceException", { enumerable: true, get: function () { return S3ServiceException_1.S3ServiceException; } });
-- parsed --
{
exports: [ '__esModule', 'S3ServiceException', [length]: 2 ],
reexports: [
'./S3Client',
'./S3',
'./commands',
'./pagination',
'./waiters',
'./models',
[length]: 6
]
}
--
XXX IITM getCjsExports of url file:///Users/trentm/tmp/iitm-node20-exports/node_modules/@aws-sdk/client-s3/dist-cjs/index.js
-- source --
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.S3ServiceException = void 0;
const tslib_1 = require("tslib");
tslib_1.__exportStar(require("./S3Client"), exports);
tslib_1.__exportStar(require("./S3"), exports);
tslib_1.__exportStar(require("./commands"), exports);
tslib_1.__exportStar(require("./pagination"), exports);
tslib_1.__exportStar(require("./waiters"), exports);
tslib_1.__exportStar(require("./models"), exports);
var S3ServiceException_1 = require("./models/S3ServiceException");
Object.defineProperty(exports, "S3ServiceException", { enumerable: true, get: function () { return S3ServiceException_1.S3ServiceException; } });
-- parsed --
{
exports: [ '__esModule', 'S3ServiceException', [length]: 2 ],
reexports: [
'./S3Client',
'./S3',
'./commands',
'./pagination',
'./waiters',
'./models',
[length]: 6
]
}
--
file:///Users/trentm/tmp/iitm-node20-exports/foo.mjs:1
import { S3Client, ListBucketsCommand } from '@aws-sdk/client-s3';
^^^^^^^^^^^^^^^^^^
SyntaxError: The requested module '@aws-sdk/client-s3' does not provide an export named 'ListBucketsCommand'
at ModuleJob._instantiate (node:internal/modules/esm/module_job:122:21)
at async ModuleJob.run (node:internal/modules/esm/module_job:188:5)
Node.js v20.2.0
import-in-the-middle hooking of a CommonJS module that has reexports breaks usage of that module. For example:
Steps to Reproduce the Problem
{ "name": "iitm-node20-exports", "version": "1.0.0", "license": "MIT", "dependencies": { "@aws-sdk/client-s3": "^3.363.0", "import-in-the-middle": "^1.4.1" } }details
Adding this console.log to import-in-the-middle/lib/get-exports.js:
and re-running:
That shows the "reexports" I'm referring to.
I was kind of surprised that
cjs-module-lexerrecognizedtslib_1.__exportStar(require("./S3Client"), exports);and similar as a "reexport". Does it have particular smarts abouttslibor is it parsing and/or executing tslib?Does import-in-the-middle want/need to get into recursively handling these "reexports"?