Closed arcticfly closed 1 year ago
Hello @arcticfly 😄 , sorry for the typo in the browser
part, decided to scrap it entirely, replacing it with exports
.
npm i @dqbd/tiktoken@^1.0.0
Thanks for getting back to me. When I run this with version 1.0.0, I get the following error:
ERROR in ./node_modules/@dqbd/tiktoken/tiktoken_bg.wasm 1:0
Module parse failed: Unexpected character '' (1:0)
The module seem to be a WebAssembly module, but module is not flagged as WebAssembly module for webpack.
BREAKING CHANGE: Since webpack 5 WebAssembly is not enabled by default and flagged as experimental feature.
You need to enable one of the WebAssembly experiments via 'experiments.asyncWebAssembly: true' (based on async modules) or 'experiments.syncWebAssembly: true' (like webpack 4, deprecated).
For files that transpile to WebAssembly, make sure to set the module type in the 'module.rules' section of the config (e. g. 'type: "webassembly/async"').
(Source code omitted for this binary file)
@ ./node_modules/@dqbd/tiktoken/tiktoken.js 1:0-43 3:15-19
@ ./src/pages/Popup/TextToJS.tsx 16:0-52 18:12-30
@ ./src/pages/Popup/Popup.tsx 12:0-34 28:212-220
@ ./src/pages/Popup/index.jsx 10:0-28 14:26-31
webpack 5.75.0 compiled with 1 error in 7602 ms
It seems like you need to add asyncWebAssembly
in your Webpack configuration, see: https://github.com/dqbd/tiktoken/tree/main/js#nextjs for NextJS for instance.
Are you using a (meta)framework of sorts? Create React App or something similar?
I'm building a chrome extension that's based on Create React App. This error did go away after I added
experiments: {
asyncWebAssembly: true,
},
To my webpack.config.js
file.
Unfortunately, I then faced an issue specific to Chrome extensions with content security:
Uncaught (in promise) CompileError: WebAssembly.instantiateStreaming(): Refused to compile or instantiate WebAssembly module because neither 'wasm-eval' nor 'unsafe-eval' is an allowed source of script in the following Content Security Policy directive: "script-src 'self'"
I resolved this by editing the content security policy in my extension's manifest.json
according to this post: https://groups.google.com/a/chromium.org/g/chromium-extensions/c/sJiaTnFMLHQ/m/y-qT1gplHwAJ
Thank you for helping me through this! I'll probably be back later with more questions.
Glad it helped! Closing this issue for now.
Thanks for making this extension!
I'm currently trying to import the @dqbd/tiktoken npm package in a React-based Chrome extension, and I'm running into the following error when I try to load my extension:
Has anyone seen this before? It seems that the npm package may not be getting compiled correctly, since the
.mjs
files referenced in package.json's export block don't seem to exist: