Issue with webpack minimization #28

Closed
opened 2026-02-15 17:05:48 -05:00 by yindo · 15 comments
Owner

Originally created by @claritise on GitHub (May 24, 2024).

Obfuscated errors get thrown when the package is included in a minified webpack, I haven't been able to dig deep but it seems to be fixed if the minimize parameter is disabled in the webpack config.

Originally created by @claritise on GitHub (May 24, 2024). Obfuscated errors get thrown when the package is included in a minified webpack, I haven't been able to dig deep but it seems to be fixed if the minimize parameter is disabled in the webpack config.
yindo closed this issue 2026-02-15 17:05:48 -05:00
Author
Owner

@digiorgiu commented on GitHub (May 28, 2024):

I am having the same issue using LangGraph in a NextJS App Route Handler. After building the app (nextjs by default minifies the app via webpack) an "EmptyChannelError" is thrown. Building the app with minification set to false solves the issue.

@digiorgiu commented on GitHub (May 28, 2024): I am having the same issue using LangGraph in a NextJS App Route Handler. After building the app (nextjs by default minifies the app via webpack) an "EmptyChannelError" is thrown. Building the app with minification set to false solves the issue.
Author
Owner

@marcbordessoule commented on GitHub (Jun 13, 2024):

Same error for me with LangGraph in a NextJS App on Vercel :

Work well locally (dev)
but "EmptyChannelError" on vercel.com (production) even if the minimize option is disabled

EmptyChannelError: 
at (node_modules/@langchain/langgraph/dist/channels/ephemeral_value.js:56:0) 
at (node_modules/@langchain/langgraph/dist/channels/base.js:21:0) 
at (node_modules/@langchain/langgraph/dist/pregel/index.js:563:30) 
at (node_modules/@langchain/langgraph/dist/pregel/read.js:54:0) 
at (node_modules/@langchain/langgraph/dist/graph/state.js:248:31) 
at (node_modules/@langchain/langgraph/dist/graph/graph.js:39:0) 
at (node_modules/@langchain/langgraph/dist/graph/graph.js:35:0) 
at (node_modules/@langchain/core/dist/runnables/base.js:210:0) 
at (node_modules/@langchain/langgraph/dist/utils.js:59:0) 
at (node_modules/@langchain/core/dist/runnables/base.js:1125:0) { name: 'EmptyChannelError' }

---- nex.config.js ------------------------------

module.exports = withBundleAnalyzer({
    webpack: (config) => {
      config.optimization.minimize = false;
      config.optimization.minimizer = [];
      return config
    },
})

---- main code ------------------------------

const model = new ChatOpenAI({
    temperature: 0,
    // Set streaming to true to enable streaming
    streaming: true,
});

interface IState {
    messages: BaseMessage[];
  }

const graphState: StateGraphArgs<IState>["channels"] = {
    messages: {
        value: (x: BaseMessage[], y: BaseMessage[]) => x.concat(y),
        default: () => [],
    },
};

const tools = [new TavilySearchResults({ maxResults: 1, verbose: true })];
const toolNode = new ToolNode<IState>(tools);

const boundModel = model.bindTools(tools);

const callModel = async (state: IState, config?: RunnableConfig) => {
    const { messages } = state;
    const prompt = ChatPromptTemplate.fromMessages([
      ["system", MAIN_ASSISTANT_PROMPT],
      new MessagesPlaceholder("messages"),
    ]);
    const response = await prompt.pipe(boundModel).invoke({ messages }, config);
    return { messages: [response] };
};

const shouldContinue = (state: IState): "tools" | typeof END => {
    const messages = state.messages;
    const lastMessage = messages[messages.length - 1];
    // If the LLM makes a tool call, then we route to the "tools" node
    if (lastMessage.additional_kwargs.tool_calls) {
      return "tools";
    }
    // Otherwise, we stop (reply to the user)
    return END;
}



const workflow = new StateGraph<IState>({ channels: graphState }) 
.addNode("llm", callModel)
.addNode("tools", toolNode)
.addEdge(START, "llm")
.addConditionalEdges("llm",shouldContinue)
.addEdge("tools", "llm")

@marcbordessoule commented on GitHub (Jun 13, 2024): Same error for me with LangGraph in a NextJS App on Vercel : Work well locally (dev) but "EmptyChannelError" on vercel.com (production) even if the minimize option is disabled ``` EmptyChannelError: at (node_modules/@langchain/langgraph/dist/channels/ephemeral_value.js:56:0) at (node_modules/@langchain/langgraph/dist/channels/base.js:21:0) at (node_modules/@langchain/langgraph/dist/pregel/index.js:563:30) at (node_modules/@langchain/langgraph/dist/pregel/read.js:54:0) at (node_modules/@langchain/langgraph/dist/graph/state.js:248:31) at (node_modules/@langchain/langgraph/dist/graph/graph.js:39:0) at (node_modules/@langchain/langgraph/dist/graph/graph.js:35:0) at (node_modules/@langchain/core/dist/runnables/base.js:210:0) at (node_modules/@langchain/langgraph/dist/utils.js:59:0) at (node_modules/@langchain/core/dist/runnables/base.js:1125:0) { name: 'EmptyChannelError' } ``` ---- nex.config.js ------------------------------ ``` module.exports = withBundleAnalyzer({ webpack: (config) => { config.optimization.minimize = false; config.optimization.minimizer = []; return config }, }) ``` ---- main code ------------------------------ ``` const model = new ChatOpenAI({ temperature: 0, // Set streaming to true to enable streaming streaming: true, }); interface IState { messages: BaseMessage[]; } const graphState: StateGraphArgs<IState>["channels"] = { messages: { value: (x: BaseMessage[], y: BaseMessage[]) => x.concat(y), default: () => [], }, }; const tools = [new TavilySearchResults({ maxResults: 1, verbose: true })]; const toolNode = new ToolNode<IState>(tools); const boundModel = model.bindTools(tools); const callModel = async (state: IState, config?: RunnableConfig) => { const { messages } = state; const prompt = ChatPromptTemplate.fromMessages([ ["system", MAIN_ASSISTANT_PROMPT], new MessagesPlaceholder("messages"), ]); const response = await prompt.pipe(boundModel).invoke({ messages }, config); return { messages: [response] }; }; const shouldContinue = (state: IState): "tools" | typeof END => { const messages = state.messages; const lastMessage = messages[messages.length - 1]; // If the LLM makes a tool call, then we route to the "tools" node if (lastMessage.additional_kwargs.tool_calls) { return "tools"; } // Otherwise, we stop (reply to the user) return END; } const workflow = new StateGraph<IState>({ channels: graphState }) .addNode("llm", callModel) .addNode("tools", toolNode) .addEdge(START, "llm") .addConditionalEdges("llm",shouldContinue) .addEdge("tools", "llm") ```
Author
Owner

@adamszeptycki commented on GitHub (Jun 17, 2024):

Same problem here.
Makes it a problem to deploy my app anywhere.

@adamszeptycki commented on GitHub (Jun 17, 2024): Same problem here. Makes it a problem to deploy my app anywhere.
Author
Owner

@alenoir commented on GitHub (Jun 17, 2024):

Same her, when I remove addConditionalEdges it works.

@alenoir commented on GitHub (Jun 17, 2024): Same her, when I remove `addConditionalEdges` it works.
Author
Owner

@adamszeptycki commented on GitHub (Jun 17, 2024):

well I kinda need conditional edge

@adamszeptycki commented on GitHub (Jun 17, 2024): well I kinda need conditional edge
Author
Owner

@alenoir commented on GitHub (Jun 17, 2024):

Me too, I have disabled webpack optimization for now, but this isn't sustainable.

@alenoir commented on GitHub (Jun 17, 2024): Me too, I have disabled webpack optimization for now, but this isn't sustainable.
Author
Owner

@rossanodr commented on GitHub (Jun 18, 2024):

I'm having the same problem

@rossanodr commented on GitHub (Jun 18, 2024): I'm having the same problem
Author
Owner

@marcbordessoule commented on GitHub (Jun 19, 2024):

Me too, I have disabled webpack optimization for now, but this isn't sustainable.

Can I ask how you disabled webpack optimization?
I modified next.config.js like this:

module.exports = withBundleAnalyzer({
    webpack: (config) => {
      config.optimization.minimize = false;
      config.optimization.minimizer = [];
      return config
    },
})

I got the message in the deployment log:

>Production code optimization has been disabled in your project.

But still the same error :-(

thanks

@marcbordessoule commented on GitHub (Jun 19, 2024): > Me too, I have disabled webpack optimization for now, but this isn't sustainable. Can I ask how you disabled webpack optimization? I modified next.config.js like this: ``` module.exports = withBundleAnalyzer({ webpack: (config) => { config.optimization.minimize = false; config.optimization.minimizer = []; return config }, }) ``` I got the message in the deployment log: `>Production code optimization has been disabled in your project. ` But still the same error :-( thanks
Author
Owner

@alenoir commented on GitHub (Jun 19, 2024):

Me too, I have disabled webpack optimization for now, but this isn't sustainable.

Can I ask how you disabled webpack optimization? I modified next.config.js like this:

module.exports = withBundleAnalyzer({
    webpack: (config) => {
      config.optimization.minimize = false;
      config.optimization.minimizer = [];
      return config
    },
})

I got the message in the deployment log:

>Production code optimization has been disabled in your project.

But still the same error :-(

thanks

webpack: (config, { isServer }) => {
    if (isServer) {
      config.plugins = [...config.plugins, new PrismaPlugin()]; 
    }

    return {
      ...config,
      optimization: {
        minimize: false,
      },
    };
},
@alenoir commented on GitHub (Jun 19, 2024): > > Me too, I have disabled webpack optimization for now, but this isn't sustainable. > > Can I ask how you disabled webpack optimization? I modified next.config.js like this: > > ``` > module.exports = withBundleAnalyzer({ > webpack: (config) => { > config.optimization.minimize = false; > config.optimization.minimizer = []; > return config > }, > }) > ``` > > I got the message in the deployment log: > > `>Production code optimization has been disabled in your project. ` > > But still the same error :-( > > thanks ```ts webpack: (config, { isServer }) => { if (isServer) { config.plugins = [...config.plugins, new PrismaPlugin()]; } return { ...config, optimization: { minimize: false, }, }; }, ```
Author
Owner

@rossanodr commented on GitHub (Jun 19, 2024):

I get this error when I try to use optimization: {
minimize: false,
},
`<--- Last few GCs --->

[13780:000001F833CC1440] 28841 ms: Mark-Compact (reduce) 3829.0 (4046.6) -> 3829.0 (4019.6) MB, 199.38 / 0.00 ms (average mu = 0.114, current mu = 0.000) last resort; GC in old space requested
[13780:000001F833CC1440] 29067 ms: Mark-Compact 3882.1 (4072.6) -> 3882.0 (4061.6) MB, 148.61 / 0.00 ms (average mu = 0.232, current mu = 0.342) allocation failure; GC in old space requested

<--- JS stacktrace --->

FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory
----- Native stack trace -----

1: 00007FF703D86E7B node::SetCppgcReference+16075
2: 00007FF703CFD996 v8::base::CPU::num_virtual_address_bits+79190
3: 00007FF703CFFBA5 v8::base::CPU::num_virtual_address_bits+87909
4: 00007FF70476D9E1 v8::Isolate::ReportExternalAllocationLimitReached+65
5: 00007FF704757178 v8::Function::Experimental_IsNopFunction+1336
6: 00007FF7045B8AA0 v8::Platform::SystemClockTimeMillis+659328
7: 00007FF7045C4D23 v8::Platform::SystemClockTimeMillis+709123
8: 00007FF7045C2684 v8::Platform::SystemClockTimeMillis+699236
9: 00007FF7045B57C0 v8::Platform::SystemClockTimeMillis+646304
10: 00007FF7045CAE3A v8::Platform::SystemClockTimeMillis+733978
11: 00007FF7045CB6B7 v8::Platform::SystemClockTimeMillis+736151
12: 00007FF7045D42EE v8::Platform::SystemClockTimeMillis+772046
13: 00007FF7045E4E3A v8::Platform::SystemClockTimeMillis+840474
14: 00007FF7045E9908 v8::Platform::SystemClockTimeMillis+859624
15: 00007FF704360FF2 v8::base::Thread::StartSynchronously+372274
16: 00007FF70477809D v8::String::Utf8Length+141
17: 00007FF703D2BD4E node::Buffer::New+3454
18: 00007FF704723F0E v8::SharedValueConveyor::SharedValueConveyor+416270
19: 00007FF704723B0A v8::SharedValueConveyor::SharedValueConveyor+415242
20: 00007FF704723DCF v8::SharedValueConveyor::SharedValueConveyor+415951
21: 00007FF704723C40 v8::SharedValueConveyor::SharedValueConveyor+415552
22: 00007FF70481EEAE v8::PropertyDescriptor::writable+676878
23: 00007FF6857CEC5D`

:(

@rossanodr commented on GitHub (Jun 19, 2024): I get this error when I try to use optimization: { minimize: false, }, `<--- Last few GCs ---> [13780:000001F833CC1440] 28841 ms: Mark-Compact (reduce) 3829.0 (4046.6) -> 3829.0 (4019.6) MB, 199.38 / 0.00 ms (average mu = 0.114, current mu = 0.000) last resort; GC in old space requested [13780:000001F833CC1440] 29067 ms: Mark-Compact 3882.1 (4072.6) -> 3882.0 (4061.6) MB, 148.61 / 0.00 ms (average mu = 0.232, current mu = 0.342) allocation failure; GC in old space requested <--- JS stacktrace ---> FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory ----- Native stack trace ----- 1: 00007FF703D86E7B node::SetCppgcReference+16075 2: 00007FF703CFD996 v8::base::CPU::num_virtual_address_bits+79190 3: 00007FF703CFFBA5 v8::base::CPU::num_virtual_address_bits+87909 4: 00007FF70476D9E1 v8::Isolate::ReportExternalAllocationLimitReached+65 5: 00007FF704757178 v8::Function::Experimental_IsNopFunction+1336 6: 00007FF7045B8AA0 v8::Platform::SystemClockTimeMillis+659328 7: 00007FF7045C4D23 v8::Platform::SystemClockTimeMillis+709123 8: 00007FF7045C2684 v8::Platform::SystemClockTimeMillis+699236 9: 00007FF7045B57C0 v8::Platform::SystemClockTimeMillis+646304 10: 00007FF7045CAE3A v8::Platform::SystemClockTimeMillis+733978 11: 00007FF7045CB6B7 v8::Platform::SystemClockTimeMillis+736151 12: 00007FF7045D42EE v8::Platform::SystemClockTimeMillis+772046 13: 00007FF7045E4E3A v8::Platform::SystemClockTimeMillis+840474 14: 00007FF7045E9908 v8::Platform::SystemClockTimeMillis+859624 15: 00007FF704360FF2 v8::base::Thread::StartSynchronously+372274 16: 00007FF70477809D v8::String::Utf8Length+141 17: 00007FF703D2BD4E node::Buffer::New+3454 18: 00007FF704723F0E v8::SharedValueConveyor::SharedValueConveyor+416270 19: 00007FF704723B0A v8::SharedValueConveyor::SharedValueConveyor+415242 20: 00007FF704723DCF v8::SharedValueConveyor::SharedValueConveyor+415951 21: 00007FF704723C40 v8::SharedValueConveyor::SharedValueConveyor+415552 22: 00007FF70481EEAE v8::PropertyDescriptor::writable+676878 23: 00007FF6857CEC5D` :(
Author
Owner

@alenoir commented on GitHub (Jun 19, 2024):

Yes me too, but you can allocate more memory with export NODE_OPTIONS=--max_old_space_size=8192

@alenoir commented on GitHub (Jun 19, 2024): Yes me too, but you can allocate more memory with `export NODE_OPTIONS=--max_old_space_size=8192`
Author
Owner

@marcbordessoule commented on GitHub (Jun 19, 2024):

Me too, I have disabled webpack optimization for now, but this isn't sustainable.

Can I ask how you disabled webpack optimization? I modified next.config.js like this:

module.exports = withBundleAnalyzer({
    webpack: (config) => {
      config.optimization.minimize = false;
      config.optimization.minimizer = [];
      return config
    },
})

I got the message in the deployment log:
>Production code optimization has been disabled in your project.
But still the same error :-(
thanks

webpack: (config, { isServer }) => {
    if (isServer) {
      config.plugins = [...config.plugins, new PrismaPlugin()]; 
    }

    return {
      ...config,
      optimization: {
        minimize: false,
      },
    };
},

Thank you so much (Merci :-).
But the problem must be elsewhere for me. It still doesn't work :-(

@marcbordessoule commented on GitHub (Jun 19, 2024): > > > Me too, I have disabled webpack optimization for now, but this isn't sustainable. > > > > > > Can I ask how you disabled webpack optimization? I modified next.config.js like this: > > ``` > > module.exports = withBundleAnalyzer({ > > webpack: (config) => { > > config.optimization.minimize = false; > > config.optimization.minimizer = []; > > return config > > }, > > }) > > ``` > > > > > > > > > > > > > > > > > > > > > > > > I got the message in the deployment log: > > `>Production code optimization has been disabled in your project. ` > > But still the same error :-( > > thanks > > ```ts > webpack: (config, { isServer }) => { > if (isServer) { > config.plugins = [...config.plugins, new PrismaPlugin()]; > } > > return { > ...config, > optimization: { > minimize: false, > }, > }; > }, > ``` Thank you so much (Merci :-). But the problem must be elsewhere for me. It still doesn't work :-(
Author
Owner

@rossanodr commented on GitHub (Jun 19, 2024):

Me too, I have disabled webpack optimization for now, but this isn't sustainable.

Can I ask how you disabled webpack optimization? I modified next.config.js like this:

module.exports = withBundleAnalyzer({
    webpack: (config) => {
      config.optimization.minimize = false;
      config.optimization.minimizer = [];
      return config
    },
})

I got the message in the deployment log:
>Production code optimization has been disabled in your project.
But still the same error :-(
thanks

webpack: (config, { isServer }) => {
    if (isServer) {
      config.plugins = [...config.plugins, new PrismaPlugin()]; 
    }

    return {
      ...config,
      optimization: {
        minimize: false,
      },
    };
},

Thank you so much (Merci :-). But the problem must be elsewhere for me. It still doesn't work :-(

To me the promlem was with addConditionalEdges. As soon I removed it works

@rossanodr commented on GitHub (Jun 19, 2024): > > > > Me too, I have disabled webpack optimization for now, but this isn't sustainable. > > > > > > > > > Can I ask how you disabled webpack optimization? I modified next.config.js like this: > > > ``` > > > module.exports = withBundleAnalyzer({ > > > webpack: (config) => { > > > config.optimization.minimize = false; > > > config.optimization.minimizer = []; > > > return config > > > }, > > > }) > > > ``` > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > I got the message in the deployment log: > > > `>Production code optimization has been disabled in your project. ` > > > But still the same error :-( > > > thanks > > > > > > ```ts > > webpack: (config, { isServer }) => { > > if (isServer) { > > config.plugins = [...config.plugins, new PrismaPlugin()]; > > } > > > > return { > > ...config, > > optimization: { > > minimize: false, > > }, > > }; > > }, > > ``` > > Thank you so much (Merci :-). But the problem must be elsewhere for me. It still doesn't work :-( To me the promlem was with addConditionalEdges. As soon I removed it works
Author
Owner

@bharathvaj-ganesan commented on GitHub (Jun 20, 2024):

I marked Langraph as external server package in next config file and it solved this EmptyChannelError issue.

https://nextjs.org/docs/app/api-reference/next-config-js/serverComponentsExternalPackages

// next.config.js
export default {
  reactStrictMode: true,
  experimental: {
    serverComponentsExternalPackages: ['@langchain/langgraph'],
  },
};
@bharathvaj-ganesan commented on GitHub (Jun 20, 2024): I marked Langraph as external server package in next config file and it solved this `EmptyChannelError` issue. https://nextjs.org/docs/app/api-reference/next-config-js/serverComponentsExternalPackages ```js // next.config.js export default { reactStrictMode: true, experimental: { serverComponentsExternalPackages: ['@langchain/langgraph'], }, }; ```
Author
Owner

@alenoir commented on GitHub (Jun 20, 2024):

@bharathvaj-ganesan thank you it works for me too 🔥

@alenoir commented on GitHub (Jun 20, 2024): @bharathvaj-ganesan thank you it works for me too 🔥
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langchain-ai/langgraphjs#28