-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Getting ERR_PACKAGE_PATH_NOT_EXPORTED]: No "exports" main defined #185
Comments
Same issue as well. The "./embeddings": {
"import": "./embeddings.mjs",
"default": "./embeddings.js"
}, to "./embeddings": {
"types": "./embeddings.d.ts",
"import": "./embeddings.js"
}, |
The langchain package is now ESM only. You can fix that by adding |
@nfcampos I'm not sure I understand why this requirement exists. Is this on purpose or will this be changed? Happy to open up a PR with the fix if that would be accepted. |
@irl-dan we converted the package to ESM so that we can support other environments outside of Node, which are ESM only, discussion here #152 You also have the option to use it without |
Hello. Using dynamic import on my side produce the same error.
and
tsconfig.json:
node version: v18.12.1 Any idea ? Note that changing es2017 to es2020 do not change anything to the problem. |
Some more information on your issue here https://stackoverflow.com/questions/65265420/how-to-prevent-typescript-from-transpiling-dynamic-imports-into-require A solution for you appears to be "moduleResolution": "node16", see here microsoft/TypeScript#43329 (comment) |
Thanks for the fast reply. Doing so, with :
Results in a Do you want me to create a separate issue ? |
I think the issue might be an |
Yep it is. Thanks. Can I submit a PR on the documentation for this single simple correction ? |
Yes, thank you |
Unfortunately It might not be only a documentation issue, running :
Regarding input_documents or input_document with the I feel like I might be doing something wrong. Note that the |
Ah, |
When will langchain support CommonJS? Turning my backend package into a module is problematic for many other packages that rely on CommonJS patterns. |
If it can helps someone running CommonJS (pretty common to be fair), you can import the langchains modules dynamically and without changing anything config related by using this |
I was struggling with this in a NextJS application. Fortunately, I'm in a monorepo environment and I was able to get it to work by creating a new "package" with My interface to langchain goes through the new package and NextJS is happy.
|
I was able to get around by the following codes (w/o
|
Just hitting this now, +1 to CommonJS support. The only workaround I found that "worked" is brillout, mentioned above import { import_ } from '@brillout/import';
async function main() {
const { OpenAI } = await import_('langchain');
const model = new OpenAI({ openAIApiKey: process.env.OPENAI_API_KEY!, temperature: 0.9 });
const res = await model.call(
'What would be a good company name a company that makes colorful socks?',
);
console.log(res);
} Granted, I cannot get it to actually send requests...
|
@nfcampos Encounter the same condition... |
@nfcampos I found the reason is that we missing the polyfill to node-fetch: import { import_ } from '@brillout/import'
import { Logger } from '@nestjs/common'
export const openaiTranslate = async (text: string, target: string[]) => {
// Polyfill for node-fetch
const { Headers, Request, Response } = await import_('node-fetch')
const fetch = await import_('node-fetch').then((mod) => mod.default)
if (!globalThis.fetch) globalThis.fetch = fetch
if (!globalThis.Headers) globalThis.Headers = Headers
if (!globalThis.Request) globalThis.Request = Request
if (!globalThis.Response) globalThis.Response = Response
const { OpenAI } = await import_('langchain')
const OPENAI_API_KEY = 'sk-xxx'
const model = new OpenAI({ openAIApiKey: OPENAI_API_KEY, temperature: 0.9 })
const res = await model.call(
'What would be a good company name a company that makes colorful socks?'
)
Logger.log(res)
return res
} |
I think where this is confusing is that the docs say for commonjs modules to use |
Page not found. |
Would there be interest in exporting to commons and esm? I'd be interested in taking that on. |
@imrank1 the reason we made the library ESM only is that allows us to use ESM-only dependencies. To add a commonjs export you'd have to review every existing dependency to confirm whether they are not ESM-only |
I see thanks. Curious if anyone here has a working example of nestjs to view. The options mentioned here don't work for me. When using the await method it breaks other areas of nestjs. I'll post what I have in a bit |
@imrank1 see an example here https://github.com/sullivan-sean/chat-langchainjs/ Or maybe better to look at my branch updating it to latest langchain version https://github.com/nfcampos/chat-langchainjs/tree/nc/lc0037 |
Thanks, the first reference worked for me. Your fork off of the latest threw an error for me.
Let me know if should log an issue in your fork? |
@imrank1 ah thanks for letting me know, I've pushed a commit fixing that. the version of hnswlib-node needed to be updated |
Verified it works! |
Also found this problematic given that top level awaits aren't allowed. It prevents extending any of the base classes like below: const { BaseDocumentLoader } = await import('langchain/document_loaders');
export default class SanitizeHtmlLoader extends BaseDocumentLoader {
} |
Hi folks, we have an open PR adding CJS support #626. If you want to give it a try you can install the prerelease version with |
I can confirm this worked for me as well. thanks! |
Hi, we've released the new version 0.0.49 which adds a CJS build and fixes this issue. |
I really can't get this to work. I'm using 0.0.50. It has issues with typescript it seems.
Anyone else have the same issues? |
@nfcampos |
Hello, I encountered this same error, I deleted my |
I added
Here is the simple code
Anyone have the same issue? |
Seems this doesn't work for me. I am using node v.22 |
We are getting
Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: No "exports" main defined in langchain\package.json
It started happening from versions 0.0.13 and up.
It works fine for 0.0.12.
The text was updated successfully, but these errors were encountered: