dqbd / tiktoken

JS port and JS/WASM bindings for openai/tiktoken
MIT License
649 stars 49 forks source link

[Error] Unexpected character '' (Note that you need plugins to import files that are not JavaScript) #31

Closed jorge-vnarvaez closed 1 year ago

jorge-vnarvaez commented 1 year ago

Hi there, i'm currently using chatgpt package from npm. The problem is when i try to import chagpt package into vue or js files this error appears on my console. Following this, the following detail appears

[Error] Unexpected character '' (Note that you need plugins to import files that are not JavaScript)

C:\Users\Jorge\Desktop\interfaces\gpt_suggestions\node_modules\@dqbd\tiktoken\tiktoken_bg.wasm:1:0 1: asm☺☺�☻&♥⌂⌂⌂☺⌂☻⌂⌂☺⌂☻⌂⌂☺⌂♥⌂⌂⌂♦⌂⌂⌂⌂☺⌂☺⌂♠⌂⌂⌂⌂⌂⌂♣⌂⌂⌂⌂⌂♥⌂⌂⌂☺~♦⌂⌂⌂⌂☺⌂♣⌂⌂⌂⌂⌂☺⌂⌂⌂⌂⌂⌂⌂⌂``☺⌂☺~♠⌂⌂⌂⌂⌂⌂☺⌂♦~~⌂⌂☺~♣⌂⌂⌂~⌂⌂⌂⌂⌂⌂⌂⌂☺⌂☻⌂⌂☺~☺⌂☻⌂~☺⌂ ^ 2: ⌂⌂⌂⌂⌂⌂⌂⌂⌂⌂☺⌂ ⌂⌂⌂⌂⌂⌂~~~♥~⌂⌂☺⌂♥⌂⌂~♦⌂⌂⌂~‼⌂⌂⌂⌂⌂⌂⌂⌂⌂⌂⌂⌂⌂⌂⌂⌂⌂⌂⌂☺⌂☼⌂⌂⌂⌂⌂⌂⌂⌂⌂⌂⌂⌂⌂⌂⌂☺⌂♂⌂⌂⌂⌂⌂⌂⌂⌂⌂⌂⌂☺⌂⌂⌂⌂⌂⌂⌂⌂⌂⌂♣⌂⌂|⌂⌂♦⌂|⌂⌂♣⌂⌂~⌂⌂♦⌂~⌂⌂♣⌂⌂}⌂⌂♦⌂}⌂⌂☻⌂~☻�☻►./tiktoken_bg.js→wbindgen_object_drop_ref♥►./tiktoken_bg.js↨wbindgen_is_undefined♠►./tiktoken_bg.js wbg_stringify_029a979dfb73aa17♠►./tiktoken_bg.js§__wbindgen_string_get☻►./tiktoken_bg.js¶wbindgen_error_new☺►./tiktoken_bg.js∟__wbg_parse_3ac95b51fc312db8☺►./tiktoken_bg.js►__wbindgen_throw☻♥�♠�♣♦♦☻♦▬♣♦♠♣☻♣☻♦♦☻♦♣♣♥☻♦3: ♦

I googled the error and read a lot of blogs but can't find a solution to this problem. Any ideas what is happening or how can i solve this?

dqbd commented 1 year ago

Hello @jorge-vnarvaez!

Sorry for the delay. In the case of Vue, assuming you are using Vite, have you tried changing the config: https://github.com/dqbd/tiktoken/tree/main/js#vite?

If you are not using Vite, may I ask for the contents of package.json? A reproducible example would be the best 👍

jorge-vnarvaez commented 1 year ago

Hi, thanks for your response.

I maked a reproducible example in this code sandbox

https://codesandbox.io/embed/competent-varahamihira-5vn0ew?fontsize=14&hidenavigation=1&theme=dark

dqbd commented 1 year ago

I see, will look into vue-cli, but at the moment, consider using vite instead.

The example provided in codesandbox uses vue-cli, vite.config.js has no effect on the build side of things unfortunately.

Also afaict vue-cli uses Webpack 4, which does not seem to have a clear path for adding WASM?

dqbd commented 1 year ago

To broaden support for non-WASM supported environments, consider using js-tiktoken, which is a pure JS port of tiktoken