langchain-ai / langchainjs

๐Ÿฆœ๐Ÿ”— Build context-aware reasoning applications ๐Ÿฆœ๐Ÿ”—
https://js.langchain.com/docs/
MIT License
11.77k stars 1.97k forks source link

Cannot use `@langchain/community` due to broken `package.json` #4084

Closed jsumners-nr closed 5 months ago

jsumners-nr commented 5 months ago
.npmrc ``` package-lock=false install-strategy=nested ```
package.json ```json { "dependencies": { "@langchain/community": "^0.0.18" } } ```
index.js ```js 'use strict' const lcc = require('@langchain/community') console.dir(lcc) ```

Using the above reproduction, running node index.js results in:

โฏโ€Šnode index.js
node:internal/modules/cjs/loader:598
      throw e;
      ^

Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: No "exports" main defined in /private/tmp/19/langchain-test/node_modules/@langchain/community/package.json
    at exportsNotFound (node:internal/modules/esm/resolve:294:10)
    at packageExportsResolve (node:internal/modules/esm/resolve:641:9)
    at resolveExports (node:internal/modules/cjs/loader:591:36)
    at Module._findPath (node:internal/modules/cjs/loader:668:31)
    at Module._resolveFilename (node:internal/modules/cjs/loader:1130:27)
    at Module._load (node:internal/modules/cjs/loader:985:27)
    at Module.require (node:internal/modules/cjs/loader:1235:19)
    at require (node:internal/modules/helpers:176:18)
    at Object.<anonymous> (/private/tmp/19/langchain-test/index.js:3:13)
    at Module._compile (node:internal/modules/cjs/loader:1376:14) {
  code: 'ERR_PACKAGE_PATH_NOT_EXPORTED'
}

Node.js v20.10.0

If we update index.js like so:

'use strict'

const lcc = require('@langchain/community/load')
console.dir(lcc)

We instead get:

โฏโ€Šnode index.js
node:internal/modules/cjs/loader:1147
  throw err;
  ^

Error: Cannot find module '@gomomento/sdk-core'
Require stack:
- /private/tmp/19/langchain-test/node_modules/@langchain/community/dist/caches/momento.cjs
- /private/tmp/19/langchain-test/node_modules/@langchain/community/dist/load/import_map.cjs
- /private/tmp/19/langchain-test/node_modules/@langchain/community/dist/load/index.cjs
- /private/tmp/19/langchain-test/node_modules/@langchain/community/load.cjs
- /private/tmp/19/langchain-test/index.js
    at Module._resolveFilename (node:internal/modules/cjs/loader:1144:15)
    at Module._load (node:internal/modules/cjs/loader:985:27)
    at Module.require (node:internal/modules/cjs/loader:1235:19)
    at require (node:internal/modules/helpers:176:18)
    at Object.<anonymous> (/private/tmp/19/langchain-test/node_modules/@langchain/community/dist/caches/momento.cjs:5:20)
    at Module._compile (node:internal/modules/cjs/loader:1376:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1435:10)
    at Module.load (node:internal/modules/cjs/loader:1207:32)
    at Module._load (node:internal/modules/cjs/loader:1023:12)
    at Module.require (node:internal/modules/cjs/loader:1235:19) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '/private/tmp/19/langchain-test/node_modules/@langchain/community/dist/caches/momento.cjs',
    '/private/tmp/19/langchain-test/node_modules/@langchain/community/dist/load/import_map.cjs',
    '/private/tmp/19/langchain-test/node_modules/@langchain/community/dist/load/index.cjs',
    '/private/tmp/19/langchain-test/node_modules/@langchain/community/load.cjs',
    '/private/tmp/19/langchain-test/index.js'
  ]
}

Node.js v20.10.0
dosubot[bot] commented 5 months ago

๐Ÿค–

Hey there, @jsumners-nr! Good to see you again. I see you've run into another issue. Let's dive in and see what we can do.

The ERR_PACKAGE_PATH_NOT_EXPORTED error is thrown when a package's package.json file has an exports field, but the requested module path is not defined in this field. In your case, it seems like the @langchain/community package's package.json file does not define a main export, which is why you're seeing this error when you try to import the package using require('@langchain/community').

To resolve this issue, you should import the specific module path that is defined in the exports field of the @langchain/community package's package.json file. For example, if the exports field looks like this:

"exports": {
  "./load": {
    "import": "./dist/load/index.js",
    "require": "./dist/load/index.cjs"
  }
}

You should import the package like this:

const lcc = require('@langchain/community/load')

The MODULE_NOT_FOUND error is thrown when Node.js cannot find a module that you're trying to import. In your case, it seems like the @langchain/community package is trying to import the @gomomento/sdk-core package, but it's not installed in your project.

To resolve this issue, you should install the @gomomento/sdk-core package by running the following command in your terminal:

npm install @gomomento/sdk-core --save

Or if you're using Yarn:

yarn add @gomomento/sdk-core

After running this command, the @gomomento/sdk-core package should be added to your dependencies in the package.json file, and the MODULE_NOT_FOUND error should be resolved.

Please try these solutions and let me know if you're still encountering any issues. If you have any other questions or need further clarification, feel free to ask.

Best regards, Dosu

Sources


This response is meant to be useful and save you time. It is not meant to be a precise solution, but rather a starting point for your own research.

Help me be more useful! Please leave a ๐Ÿ‘ if this is helpful and ๐Ÿ‘Ž if it is irrelevant.

If you want to continue the conversation, start your reply with @dosu-bot.

jsumners-nr commented 5 months ago

Please go away bot. I want a human to look at this.

dosubot[bot] commented 5 months ago

๐Ÿค–

It seems like this issue requires a deeper look, @jacoblee93 could you please lend your expertise?


This response is meant to be useful and save you time. It is not meant to be a precise solution, but rather a starting point for your own research.

Help me be more useful! Please leave a ๐Ÿ‘ if this is helpful and ๐Ÿ‘Ž if it is irrelevant.

If you want to continue the conversation, start your reply with @dosu-bot.

jacoblee93 commented 5 months ago

Thanks for the report!

I suppose the error could be clearer, but this is by design as there is no default entrypoint for @langchain/community.

jsumners-nr commented 5 months ago

Then how is this package supposed to be used?

jacoblee93 commented 5 months ago

See e.g. https://js.langchain.com/docs/integrations/chat/fireworks