ollama / ollama-js

Ollama JavaScript library
https://ollama.ai
MIT License
1.56k stars 103 forks source link

Cannot find module 'ollama/browser' or its corresponding type declarations. #104

Closed pplonski closed 2 weeks ago

pplonski commented 2 weeks ago

Hi there,

Thank you for this project! I'm using it to create typescript package that is used in jupyter notebook extension. I would like to use browser version, without node.

I have installed ollama and imported with code:

import ollama from "ollama/browser";

When I'm testing package in storybook stories it all works perfect. The problem is during building the package, after running yarn build I got error:

TS2307: Cannot find module 'ollama/browser' or its corresponding type declarations.

The full output:

yarn run v1.22.19
$ webpack
assets by status 725 KiB [cached] 247 assets
runtime modules 1.17 KiB 6 modules
orphan modules 42.9 KiB [orphan] 3 modules
modules by path ./src/ 684 KiB
  modules by path ./src/icons/*.tsx 111 KiB 79 modules
  modules by path ./src/recipes/ 402 KiB 69 modules
  modules by path ./src/components/ 105 KiB 16 modules
  modules by path ./src/*.css 64.7 KiB 2 modules
  + 1 module
modules by path ./node_modules/ 549 KiB
  modules by path ./node_modules/markdown-it/ 271 KiB 9 modules
  modules by path ./node_modules/style-loader/dist/runtime/*.js 5.84 KiB 6 modules
  modules by path ./node_modules/css-loader/dist/runtime/*.js 2.31 KiB 2 modules
  modules by path ./node_modules/ollama/dist/ 13.5 KiB 2 modules
  + 9 modules
external "react" 42 bytes [built] [code generated]

ERROR in /home/piotr/sandbox/extensions/piece-of-code/recipes/src/components/Chat.tsx
./src/components/Chat.tsx 5:19-35
[tsl] ERROR in /home/piotr/sandbox/extensions/piece-of-code/recipes/src/components/Chat.tsx(5,20)
      TS2307: Cannot find module 'ollama/browser' or its corresponding type declarations.
ts-loader-default_e3b0c44298fc1c14
 @ ./src/components/SelectRecipe.tsx 87:13-30
 @ ./src/index.ts 10:21-57

webpack 5.92.0 compiled with 1 error in 11332 ms
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

I would like to pack the package to use it in jupyter notebook extension, what is more, the same package will be also used on next.js website in documentation pages.

Any idea what could be wrong? Thank you for your help.

pplonski commented 2 weeks ago

I changed in tsconfig.json the following setting:

{
  "compilerOptions": {
    "module": "NodeNext",
    "moduleResolution": "NodeNext"
...

and it is working. Thank you!