diff --git a/libs/langchain-scripts/src/build_v2.ts b/libs/langchain-scripts/src/build_v2.ts index 13fc67fbb863..4c4b42653c60 100644 --- a/libs/langchain-scripts/src/build_v2.ts +++ b/libs/langchain-scripts/src/build_v2.ts @@ -490,17 +490,13 @@ function listEntrypoints(packageJson: Record) { const checkAllowSideEffects = async (entrypoint: string): Promise => { let entrypointContent: Buffer | undefined; try { - entrypointContent = await fs.promises.readFile( - `./dist/${entrypoint.replace(/^\.\//, "")}` - ); + entrypointContent = await fs.promises.readFile(`./dist/${entrypoint}.js`); // eslint-disable-next-line @typescript-eslint/no-explicit-any } catch (e: any) { if (e.message.includes("ENOENT")) { // Entrypoint is likely via an `index.js` file, retry with `index.js` appended to path entrypointContent = await fs.promises.readFile( - `./dist/${entrypoint - .replace(/^\.\//, "") - .replace(/\.js$/, "")}/index.js` + `./dist/${entrypoint}/index.js` ); } } @@ -542,7 +538,12 @@ async function checkTreeShaking(config: LangChainConfig) { let hasUnexpectedSideEffects = sideEffects.length > 0; if (hasUnexpectedSideEffects) { - hasUnexpectedSideEffects = !(await checkAllowSideEffects(entrypoint)); + // Map the entrypoint back to the actual file entrypoint using the LangChainConfig file + const actualEntrypoint = + config.entrypoints[entrypoint.replace(/^\.\/|\.js$/g, "")]; + hasUnexpectedSideEffects = !(await checkAllowSideEffects( + actualEntrypoint + )); } reportMap.set(entrypoint, { log: sideEffects,