Description
Checked other resources
- I added a very descriptive title to this issue.
- I searched the LangChain.js documentation with the integrated search.
- I used the GitHub search to find a similar question and didn't find it.
- I am sure that this is a bug in LangChain.js rather than my code.
- The bug is not resolved by updating to the latest stable version of LangChain (or the specific integration package).
Example Code
return new ChatGoogle({
model: 'gemini-2.5-flash-preview-04-17',
maxReasoningTokens: 0,
apiVersion: 'v1beta',
platformType: 'gai',
safetySettings: setSafetySettings(),
apiKey: configService.get<string>('GOOGLE_AI_API_KEY'),
});
Error Message and Stack Trace (if applicable)
/root/repo/agent/backend/node_modules/@langchain/google-webauth/dist/auth.cjs:6
const google_1 = require("web-auth-library/google");
^
Error [ERR_REQUIRE_ESM]: require() of ES Module /root/repo/agent/backend/node_modules/web-auth-library/dist/google/index.js from /root/repo/agent/backend/node_modules/@langchain/google-webauth/dist/auth.cjs not supported.
Instead change the require of index.js in /root/repo/agent/backend/node_modules/@langchain/google-webauth/dist/auth.cjs to a dynamic import() which is available in all CommonJS modules.
at Object. (/root/repo/agent/backend/node_modules/@langchain/google-webauth/dist/auth.cjs:6:18)
at Object. (/root/repo/data-agent/backend/node_modules/@langchain/google-webauth/dist/chat_models.cjs:5:19)
at Object. (/root/repo/data-agent/backend/node_modules/@langchain/google-webauth/dist/index.cjs:17:14)
at Object. (/root/repo/data-agent/backend/node_modules/@langchain/google-webauth/index.cjs:1:18)
// ... (further stack trace related to project structure)
at Object. (/root/repo/data-agent/backend/dist/main.js:4:22) {
code: 'ERR_REQUIRE_ESM'
}
Description
-
I'm trying to use the langchain library to: integrate Google services that rely on @langchain/google-webauth within a NestJS (TypeScript, CommonJS) backend application.
-
I expect to see: The application to start and run successfully, with @langchain/google-webauth functioning correctly in the CommonJS environment.
-
Instead, it does: The application fails to start (or crashes at runtime) with an Error [ERR_REQUIRE_ESM]: require() of ES Module. The error originates from @langchain/google-webauth/dist/auth.cjs attempting to require("web-auth-library/google"), which appears to be an ES Module.
System Info
├── @langchain/[email protected]
├── @langchain/[email protected]
├── @langchain/[email protected]
├── @langchain/[email protected]
├── [email protected]
node 18.20.5
Also tried with the most recent version of all the packages getting the same error