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

Issue importing submodules using es6 module import from documentation #45

Closed
dantheman0207 opened this issue Feb 18, 2023 · 7 comments
Closed

Comments

@dantheman0207
Copy link

dantheman0207 commented Feb 18, 2023

Running this code:

import { initializeAgentExecutor } from "langchain/agents";

gives me this error:

Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/Users/USERXXX/Projects/langchain/prototype/javascript/node_modules/langchain/agents' imported from /Users/USERXXX/Projects/langchain/prototype/javascript/prototype.js
Did you mean to import langchain/prototype/javascript/node_modules/langchain/agents.js?

When I add the .js to the import (like this: import { initializeAgentExecutor } from "langchain/agents.js";) it works fine. This same issue occurs for all imports I've tried. It's been a while since I worked with javascript so maybe I'm missing something in the es6 module import process that's obvious but wondering if I'm doing something wrong here or whether the documentation should be updated. I assume it should work without the .js suffix.

Running node v18.13.0 on macOS Catalina 10.15.

@nfcampos
Copy link
Collaborator

We're missing the exports key, thanks for pointing it out! we'll get it fixed

@sullivan-sean
Copy link
Collaborator

Hey there! Would love to get a little bit more info on your setup for this project. Are you using js or typescript? If typescript, could you share your tsconfig?

We used to use the exports approach, but this doesn't work with the default moduleResolution: "node" configuration (see microsoft/TypeScript#50794 (comment)). Instead we take an approach similar to nextjs where we generate a bunch of top level .js entrypoints (e.g. files like this file in the next repo)

Ideally we could continue using this approach - I have high confidence we can make it work given this is what next is doing.

You can also check out chat langchain which is an example project that imports from subpaths

@dantheman0207
Copy link
Author

dantheman0207 commented Feb 19, 2023

Thanks! I will look at the example project more. I am not using typescript, just vanilla node. The only change I made after running node init and autogenerating my package.json was adding a "type": "module", field. Here is my (lightly redacted) package.json:


{
  "name": "prototype",
  "version": "1.0.0",
  "description": "prototype of langchain in js",
  "main": "prototype.js",
  "type": "module",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "start": "node prototype.js"
  },
  "repository": {
    "type": "git",
    "url": "git+https://github.com/dantheman0207/XXX.git"
  },
  "author": "XXX",
  "bugs": {
    "url": "https://github.com/dantheman0207/XXX/issues"
  },
  "homepage": "https://github.com/dantheman0207/XXX#readme",
  "dependencies": {
    "langchain": "^0.0.7",
    "openai": "^3.1.0",
    "serpapi": "^1.1.1"
  }
}

@sullivan-sean
Copy link
Collaborator

sullivan-sean commented Feb 20, 2023

Hoping this will be solved by #54 -- I'll test with your package.json here before we merge

EDIT: a very simple repo with your package.json and import statement from above is working for me locally after that PR

@sullivan-sean
Copy link
Collaborator

This is live in version 0.0.8 - could you just double check if this is resolved on your end before I close?

@sullivan-sean
Copy link
Collaborator

Closing for now, can re-open if anyone is still encountering this issue

@dantheman0207
Copy link
Author

Sorry for the delay, couldn't get to this. Works for me!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants