Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ERR_REQUIRE_ESM]: require() of ES Module \node_modules\srt-parser-2\dist\index.js from langchain\dist\document_loaders\fs\srt.cjs not supported #4059

Closed
ladrians opened this issue Jan 17, 2024 · 4 comments
Labels
auto:bug Related to a bug, vulnerability, unexpected error with an existing feature

Comments

@ladrians
Copy link

ladrians commented Jan 17, 2024

I am trying to update to version 0.1 from 0.0.214. I am receiving the following error

C:\temp\packages\functions\node_modules\ts-node\dist\index.js:851
            return old(m, filename);
                   ^
Error [ERR_REQUIRE_ESM]: require() of ES Module C:\temp\packages\functions\node_modules\srt-parser-2\dist\index.js from C:\temp\packages\functions\node_modules\langchain\dist\document_loaders\fs\srt.cjs not supported.
Instead change the require of index.js in C:\temp\packages\functions\node_modules\langchain\dist\document_loaders\fs\srt.cjs to a dynamic import() which is available in all CommonJS modules.
    at require.extensions.<computed> [as .js] (C:\temp\packages\functions\node_modules\ts-node\dist\index.js:851:20)      
    at Object.<anonymous> (C:\temp\packages\functions\node_modules\langchain\dist\document_loaders\fs\srt.cjs:7:40)       
    at require.extensions.<computed> [as .js] (C:\temp\packages\functions\node_modules\ts-node\dist\index.js:851:20)      
    at Object.<anonymous> (C:\temp\packages\functions\node_modules\langchain\document_loaders\fs\srt.cjs:1:18)
    at require.extensions.<computed> [as .js] (C:\temp\packages\functions\node_modules\ts-node\dist\index.js:851:20)      
    at Object.<anonymous> (C:\temp\packages\functions\src\ingest-document.ts:24:15)
    at m._compile (C:\temp\packages\functions\node_modules\ts-node\dist\index.js:857:29)
    at require.extensions.<computed> [as .ts] (C:\temp\packages\functions\node_modules\ts-node\dist\index.js:859:16)      
    at Object.<anonymous> (C:\temp\packages\functions\src\controllers\upsert-doc.ts:38:27)
    at m._compile (C:\temp\packages\functions\node_modules\ts-node\dist\index.js:857:29)
    at require.extensions.<computed> [as .ts] (C:\temp\packages\functions\node_modules\ts-node\dist\index.js:859:16)      
    at Object.<anonymous> (C:\temp\packages\functions\src\server.ts:9:22)
    at m._compile (C:\temp\packages\functions\node_modules\ts-node\dist\index.js:857:29)
    at require.extensions.<computed> [as .ts] (C:\temp\packages\functions\node_modules\ts-node\dist\index.js:859:16) {    
  code: 'ERR_REQUIRE_ESM'

from this code, noticed the srt-parser-2 dependency was updated.

import { SRTLoader } from "langchain/document_loaders/fs/srt";
...
documentLoader = new  SRTLoader(filePath);
...

thanks,

Copy link

dosubot bot commented Jan 17, 2024

Hi, @ladrians,

I'm helping the langchainjs team manage their backlog and am marking this issue as stale. The issue was opened by you and is related to the srt-parser-2 dependency being updated, causing an error related to ES Module support. There were discussions about resolving the issue by changing the require of index.js in srt.cjs to a dynamic import() and trying to upgrade the peer dependency to the latest version. You confirmed that the issue persists with the latest version and provided a minimal sample to reproduce it.

Could you please confirm if this issue is still relevant to the latest version of the langchainjs repository? If it is, please let the langchainjs team know by commenting on the issue. Otherwise, feel free to close the issue yourself, or the issue will be automatically closed in 7 days.

Thank you for your understanding and cooperation. If you have any further questions or need assistance, feel free to reach out.

@dosubot dosubot bot added the auto:bug Related to a bug, vulnerability, unexpected error with an existing feature label Jan 17, 2024
@jacoblee93
Copy link
Collaborator

Does this persist if you upgrade your peer dependency to the latest version?

I think this is related to folks running into #1554. Unfortunate that there was a breaking change in a patch in that package.

Please reopen if that doesn't fix it.

@ladrians
Copy link
Author

yes it does, not sure how to WA it.

I have the latest 1.2.3 version. This is a minimal sample to reproduce it

import { SRTLoader } from "langchain/document_loaders/fs/srt";

export const run = async () => {
  const loader = new SRTLoader(
    "c:/temp/test.srt"
  );
const docs = await loader.load();
console.log(docs.length);
}
(async () => {
  await run();
})();

using ECMAScript

ts-node --esm -r dotenv/config src/scripts/sandbox.ts

the test.srt file is just

1
00:00:00,000 --> 00:00:02,000
Hello, world!

2
00:00:02,500 --> 00:00:05,000
This is a minimal SRT file.

@ladrians
Copy link
Author

@jacoblee93 if possible can you reopen it? I do not have the option.

@jacoblee93 jacoblee93 reopened this Jan 18, 2024
@dosubot dosubot bot added the stale Issue has not had recent activity or appears to be solved. Stale issues will be automatically closed label Apr 18, 2024
@dosubot dosubot bot closed this as not planned Won't fix, can't repro, duplicate, stale Apr 25, 2024
@dosubot dosubot bot removed the stale Issue has not had recent activity or appears to be solved. Stale issues will be automatically closed label Apr 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auto:bug Related to a bug, vulnerability, unexpected error with an existing feature
Projects
None yet
Development

No branches or pull requests

2 participants