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
node_modules/.pnpm/@langchain[email protected][email protected][email protected]_/node_modules/@langchain/core/output_parsers.d.cts:1:15 - error TS1479: The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("./dist/output_parsers/index.js")' call instead.
1 export * from './dist/output_parsers/index.js'
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
node_modules/.pnpm/@langchain[email protected][email protected][email protected]_/node_modules/@langchain/core/prompts.d.cts:1:15 - error TS1479: The current file is
a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("./dist/prompts/index.js")' call instead.
1 export * from './dist/prompts/index.js'
~~~~~~~~~~~~~~~~~~~~~~~~~
node_modules/.pnpm/@langchain+openai@0.3.13_@langchain+core@0._2atobctgv6vhmnci3yzbqkkle4/node_modules/@langchain/openai/index.d.cts:1:15 - error TS1479: The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("./dist/index.js")' call instead.
1 export * from './dist/index.js'
~~~~~~~~~~~~~~~~~
I am trying to build my typescript node server, but it's not building because of the langchain modules. I tried {"module": "NodeNext","moduleResolution": "bundler"}, which does build the app, but then I get even more issues running that build, such as every file not having a .js at the end, among other issues.
System Info
pnpm version 9.12.3
node version v20.12.0
Windows 10
The text was updated successfully, but these errors were encountered:
dosubotbot
added
the
auto:bug
Related to a bug, vulnerability, unexpected error with an existing feature
label
Dec 16, 2024
To address the TypeScript build errors related to CommonJS and ECMAScript module imports, you can try using dynamic imports. Modify your code to use the import() function, which returns a promise. This function can be used in an async function to import the module and use it in your code. Here's an example:
exportconstgetExamples=async(query: string,apiKey: string)=>{const{ MemoryVectorStore }=awaitimport("langchain/vectorstores/memory");const{ OpenAIEmbeddings }=awaitimport("langchain/embeddings/openai");// Rest of your code...};
Additionally, ensure that your tsconfig.json is configured correctly. You might need to set "module": "nodenext" and "moduleResolution": "nodenext" to help TypeScript understand the module system you are using and resolve imports correctly [1].
Checked other resources
Example Code
package.json
tsconfig.json
Error Message and Stack Trace (if applicable)
PS C:\Users\sajid\Desktop\med startup tests\voice_transcription\monolith> pnpm run build
node_modules/.pnpm/@langchain[email protected][email protected][email protected]_/node_modules/@langchain/core/output_parsers.d.cts:1:15 - error TS1479: The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("./dist/output_parsers/index.js")' call instead.
1 export * from './dist/output_parsers/index.js'
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
node_modules/.pnpm/@langchain[email protected][email protected][email protected]_/node_modules/@langchain/core/prompts.d.cts:1:15 - error TS1479: The current file is
a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("./dist/prompts/index.js")' call instead.
1 export * from './dist/prompts/index.js'
~~~~~~~~~~~~~~~~~~~~~~~~~
node_modules/.pnpm/@langchain+openai@0.3.13_@langchain+core@0._2atobctgv6vhmnci3yzbqkkle4/node_modules/@langchain/openai/index.d.cts:1:15 - error TS1479: The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("./dist/index.js")' call instead.
1 export * from './dist/index.js'
~~~~~~~~~~~~~~~~~
Found 3 errors in 3 files.
Errors Files
1 node_modules/.pnpm/@langchain[email protected][email protected][email protected]_/node_modules/@langchain/core/output_parsers.d.cts:1
1 node_modules/.pnpm/@langchain[email protected][email protected][email protected]_/node_modules/@langchain/core/prompts.d.cts:1
1 node_modules/.pnpm/@langchain+openai@0.3.13_@langchain+core@0._2atobctgv6vhmnci3yzbqkkle4/node_modules/@langchain/openai/index.d.cts:1
ELIFECYCLE Command failed with exit code 2.
Description
I am trying to build my typescript node server, but it's not building because of the langchain modules. I tried
{"module": "NodeNext","moduleResolution": "bundler"}
, which does build the app, but then I get even more issues running that build, such as every file not having a .js at the end, among other issues.System Info
pnpm version 9.12.3
node version v20.12.0
Windows 10
The text was updated successfully, but these errors were encountered: