langchainjs: Getting ERR_PACKAGE_PATH_NOT_EXPORTED]: No "exports" main defined
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.
About this issue
- Original URL
- State: closed
- Created a year ago
- Reactions: 14
- Comments: 35 (6 by maintainers)
The langchain package is now ESM only. You can fix that by adding
"type": "module"to yourpackage.json. You can find more information here https://hwchase17.github.io/langchainjs/docs/getting-started/When will langchain support CommonJS? Turning my backend package into a module is problematic for many other packages that rely on CommonJS patterns.
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
npm i langchain@next. Can you let me know it it works for you, before we announce for everyone?Hi, we’ve released the new version 0.0.49 which adds a CJS build and fixes this issue.
Would there be interest in exporting to commons and esm? I’d be interested in taking that on.
@irl-dan we converted the package to ESM so that we can support other environments outside of Node, which are ESM only, discussion here https://github.com/hwchase17/langchainjs/discussions/152
You also have the option to use it without
type: moduleby using dynamic import as mentioned here https://hwchase17.github.io/langchainjs/docs/getting-started/#commonjs-in-nodejs@nfcampos I found the reason is that we missing the polyfill to node-fetch:
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
importpackagehttps://www.npmjs.com/package/@brillout/import
@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.
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 i tried with langchain-0.0.49 as u mention. Path error solved but not able to use new packages. module not found
I can confirm this worked for me as well. thanks!
@imrank1 ah thanks for letting me know, I’ve pushed a commit fixing that. the version of hnswlib-node needed to be updated
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
Page not found.
I was able to get around by the following codes (w/o
type: "module"in package.json):Yes, thank you