langchain报错记录(js)
文章目录
- [ERR_PACKAGE_PATH_NOT_EXPORTED]
- 报错:
- 报错语句:
- 思路:
- 解决方法:
[ERR_PACKAGE_PATH_NOT_EXPORTED]
报错:
Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath ‘./dist/prompts/’ is not defined by “exports” in by “exports” in …\package.json
报错: import { PromptTemplate } from “langchain/dist/prompts”;
报错语句:
import { PromptTemplate } from "langchain/dist/prompts";
思路:
中文的js文档写的是import { PromptTemplate } from "langchain/prompts";
后面查找安装包的路径发现在dist下面。后面又出现了如上错误,发现是langchain中的package.json中没有export相关路径。
解决方法:
- 在对应的node_modules\langchain\package.json 里加入langchain/dist/prompts路径。已解决。
"./dist/prompts/prompt": {
"types": {
"import": "./dist/prompts/prompt.d.ts",
"require": "./dist/prompts/prompt.d.ts",
"default": "./dist/prompts/prompt.d.ts"
},
"import": "./dist/prompts/prompt.js",
"require": "./dist/prompts/prompt.cjs"
},
- 在自己的package.json中添加 “type”: “module”,但是未解决。