dqbd / tiktoken

JS port and JS/WASM bindings for openai/tiktoken
MIT License
705 stars 53 forks source link

Module not found: Can't resolve '@dqbd/tiktoken' #18

Closed ghost closed 1 year ago

ghost commented 1 year ago

I added the package using yarn add but this error won't go away, tried using npm but still persists

Module not found: Can't resolve '@dqbd/tiktoken'

https://nextjs.org/docs/messages/module-not-found

Import trace for requested module:
./pages/api/chatgpt.js
./components/form.js
./pages/index.js

image

dqbd commented 1 year ago

Hello @ameywtf, please try the newest latest version (1.0.0), which should resolve the bundling issues.

itsuka-dev commented 1 year ago

I had a similar issue as OP, so I tried upgrading to latest (1.0.2).

I couldn't get the module resolution to work on Edge runtime when I tried importing the wasm file:

import wasm from '@dqbd/tiktoken/lite/tiktoken_bg.wasm?module';
Module not found: Package path ./lite/tiktoken_bg.wasm?module is not exported from package /<project>/node_modules/@dqbd/tiktoken (see exports field in /<project>/node_modules/@dqbd/tiktoken/package.json)

However, when I switched to relative path (similar to Cloudflare Workers setup), it worked:

// src/pages/api/<route>.ts
import wasm from '../../../node_modules/@dqbd/tiktoken/lite/tiktoken_bg.wasm?module';

In the end, I made a local copy of tiktoken_bg.wasm so that I don't have to rely on node_modules.

HaleyLeoZhang commented 1 year ago

I had a similar problem at verstion 1.0.2
image

image

March 3,2023, was the last time I compiled successfully .That verstion 0.4.0
Even i rolled back tov0.4.0 and got the same result

2023-3-19 14:20:44
verstion 1.0.2
I resolved it by copy tiktoken_bg.wasm to my dist directory
1679206442048

dqbd commented 1 year ago

The issue should be fully resolved with 1.0.4.