fix(LangChain Code Node): Fix resolution of scoped langchain modules (#9258)

Signed-off-by: Oleg Ivaniv <me@olegivaniv.com>
This commit is contained in:
oleg 2024-04-30 12:23:07 +02:00 committed by GitHub
parent f6c9493355
commit 445c05dca4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -48,13 +48,14 @@ return [ {json: { output } } ];`;
const defaultCodeSupplyData = `const { WikipediaQueryRun } = require('langchain/tools');
return new WikipediaQueryRun();`;
const langchainModules = ['langchain', '@langchain/*'];
export const vmResolver = makeResolverFromLegacyOptions({
external: {
modules: external ? ['langchain', ...external.split(',')] : ['langchain'],
modules: external ? [...langchainModules, ...external.split(',')] : [...langchainModules],
transitive: false,
},
resolve(moduleName, parentDirname) {
if (moduleName.match(/^langchain\//)) {
if (moduleName.match(/^langchain\//) ?? moduleName.match(/^@langchain\//)) {
return require.resolve(`@n8n/n8n-nodes-langchain/node_modules/${moduleName}.cjs`, {
paths: [parentDirname],
});