langchain-ai / langchainjs

🦜🔗 Build context-aware reasoning applications 🦜🔗
https://js.langchain.com/docs/
MIT License
12.41k stars 2.1k forks source link

Typescript not working #340

Closed vforv closed 1 year ago

vforv commented 1 year ago

ts-node -T --logError test-init.ts

error: uncaughtException No "exports" main defined i/node_modules/langchain/package.json {"timestamp":"March-15-2023 18:43:49"}
error: uncaughtException Stack Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: No "exports" main defined in node_modules/langchain/package.json
    at new NodeError (node:internal/errors:387:5)
    at throwExportsNotFound (node:internal/modules/esm/resolve:365:9)
    at packageExportsResolve (node:internal/modules/esm/resolve:589:7)
    at resolveExports (node:internal/modules/cjs/loader:529:36)
    at Function.Module._findPath (node:internal/modules/cjs/loader:569:31)
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:981:2

I tried also deleting package.json but it just create new error

ayalpani commented 1 year ago

Mine looks like

Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './chains' is not defined by "exports" in /Users/ayalpani/dev/playground/node_modules/langchain/package.json

abhishek-codaio commented 1 year ago

Mine looks like

Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './chains' is not defined by "exports" in /Users/ayalpani/dev/playground/node_modules/langchain/package.json

I'm also seeing this: Error: Package subpath './llms' is not defined by "exports" in <PATH>/node_modules/langchain/package.json

nsbradford commented 1 year ago

Looks like https://github.com/hwchase17/langchainjs/issues/185 (response there)

indiejoseph commented 1 year ago

still not working with Typescript, even added { "type": "module" } in packages.json, and running on NodeJS v8

AuriDeimantasDev commented 1 year ago

Inline imports should fix this issue. Fx:

Before

import {VectorDBQAChain} from 'langchain/chains';

After

const {VectorDBQAChain} = await import('langchain/chains');
dankolesnikov commented 1 year ago

I am still facing this issue without a resolve. Unfortunately solution form @AuriDeimantasDev did not work for me. Facing the same error:

Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './embeddings' is not defined by "exports" in /Users/danil/Coding/shepherd-app/goldengate/node_modules/langchain/package.json
    at new NodeError (node:internal/errors:372:5)
    at throwExportsNotFound (node:internal/modules/esm/resolve:440:9)
    at packageExportsResolve (node:internal/modules/esm/resolve:664:7)
    at resolveExports (node:internal/modules/cjs/loader:483:36)
    at Function.Module._findPath (node:internal/modules/cjs/loader:523:31)
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:925:27)
    at Function.Module._resolveFilename.sharedData.moduleResolveFilenameHook.installedValue [as _resolveFilename] (/Users/danil/Coding/shepherd-app/goldengate/node_modules/@cspotcode/source-map-support/source-map-support.js:811:30)
    at Function.Module._load (node:internal/modules/cjs/loader:780:27)
    at Module.require (node:internal/modules/cjs/loader:1005:19)
    at require (node:internal/modules/cjs/helpers:102:18) {
  code: 'ERR_PACKAGE_PATH_NOT_EXPORTED'
}
JimTeva commented 1 year ago

Mine looks like Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './chains' is not defined by "exports" in /Users/ayalpani/dev/playground/node_modules/langchain/package.json

I'm also seeing this: Error: Package subpath './llms' is not defined by "exports" in <PATH>/node_modules/langchain/package.json

I got the same error then checked again requirements for typescript here and it says:

{
  "compilerOptions": {
    ...
    "target": "ES2020", // or higher
    "module": "nodenext",
  }
}

Updated my tsconfig.json then updated my package.json to add

{
  "name": "functions",
  "type": "module", <-- this
...
}

Then it worked

Marviel commented 1 year ago

have performed both fixes mentioned above and still no dice, receiving:

Error: Must use import to load ES Module: /Users/lukebechtel/localdev/lib/apps/scripts/src/agents/simple-notion-agent.ts
nfcampos commented 1 year ago

Hi, we've released a new version 0.0.49 which adds a CJS build and should fix this issue.

hilarykitz commented 12 months ago

If anyone is still stuck on this, make sure that you are explicitly stating "type": "commonjs" in package.json and "module": "CommonJS" in your tsconfig to use the CJS build. Otherwise it'll keep looking at the ESM one and erroring :)