You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When running node --loader ./hook.mjs index.mjs, the following error is produced:
file:///Users/sam.brenner/Development/ml-obs/langchain-nodejs/node_modules/langsmith/dist/index.js?iitm=true:6
const _ = Object.assign(
^
ReferenceError: RunTree is not defined
at Function.assign (<anonymous>)
at file:///Users/sam.brenner/Development/ml-obs/langchain-nodejs/node_modules/langsmith/dist/index.js?iitm=true:6:18
at ModuleJob.run (node:internal/modules/esm/module_job:262:25)
at async onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:483:26)
at async asyncRunEntryPointWithESMLoader (node:internal/modules/run_main:117:5)
Steps to Reproduce the Problem
Create a new directory, and install the following dependencies:
Context: I am working on writing some instrumentation code for LangChain, and wanted to verify it works with the import-in-the-middle hooks for ESM.
I tried to do a bit of debugging to see what exactly was going on. Pointing the hook instead to my local version of import-in-the-middle, I tried to log the namespace we're re-exporting from. Doing that, I can see the namespace that's throwing the error is:
Where it seems the problematic RunTree property is <uninitialized>. I'm not entirely sure how this happens, or if it's a product of how import-in-the-middle is interacting with the transpiled code. The original file is defined here.
Naive/noob question: would it be possible to just disable ESM parsing/loader hooks for certain files? This problematic file, from langsmith, is a sub-dependency of langchain, and is not a file I would want to instrument.
Although this does not seem to be helpful, although it's likely I'm doing it wrong 😅 Also, my understanding is that will only work for newer versions of Node, and this integration I'm writing should be compatible back through Node 16. Any insights here are appreciated, happy to follow up with any additional information!
The text was updated successfully, but these errors were encountered:
I realized that the workaround to disable ESM alltogether should be something like:
// register.mjsimport*asmodulefrom'module'module.register('import-in-the-middle/hook.mjs',import.meta.url,{data: {exclude: [/langsmith/,/openai/]}// excluding openai as well, as there is another IITM issue with that})
There still seems to be some problem with instrumenting LangChain properly, but I believe that is on me to figure out, otherwise I will follow up.
I am wondering in general if there are ways to accomplish this for the --loader method, where we cannot leverage the kind of functionality in register.mjs above, for "older" (back through 16) versions of Node. Additionally, any insight to the original issue is also appreciated, thanks! 😄
I suspect the issue you are seeing is a duplicate of one of the existing known issues. So #38 or similar to #141.
import-in-the-middle wraps modules in additional modules. It tries to create matching exports so the wrapping appears invisible but it is unable to fully replicate the behaviour of a module in a couple of cases.
Expected Behavior
Running
node --loader ./hook.mjs index.mjs
forshould not error.
Actual Behavior
When running
node --loader ./hook.mjs index.mjs
, the following error is produced:Steps to Reproduce the Problem
index.mjs
file, with the following contentshook.mjs
file, with the following contentsnode --loader ./hook.mjs index.mjs
in the current directory.Specifications
Running
npx envinfo
:Investigation
Context: I am working on writing some instrumentation code for LangChain, and wanted to verify it works with the
import-in-the-middle
hooks for ESM.I tried to do a bit of debugging to see what exactly was going on. Pointing the hook instead to my local version of
import-in-the-middle
, I tried to log thenamespace
we're re-exporting from. Doing that, I can see the namespace that's throwing the error is:Where it seems the problematic
RunTree
property is<uninitialized>
. I'm not entirely sure how this happens, or if it's a product of howimport-in-the-middle
is interacting with the transpiled code. The original file is defined here.Naive/noob question: would it be possible to just disable ESM parsing/loader hooks for certain files? This problematic file, from
langsmith
, is a sub-dependency oflangchain
, and is not a file I would want to instrument.I've tried changing my
hook.mjs
to be:Although this does not seem to be helpful, although it's likely I'm doing it wrong 😅 Also, my understanding is that will only work for newer versions of Node, and this integration I'm writing should be compatible back through Node 16. Any insights here are appreciated, happy to follow up with any additional information!
The text was updated successfully, but these errors were encountered: