-
Notifications
You must be signed in to change notification settings - Fork 785
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Bug] Typescript - Could not find a declaration file for module '@xenova/transformers' #80
Comments
will be fixed after #81 |
@warlockdn Can you test #82 to see if it works in your environment? I'll merge if it works correctly. |
I did look into this. Somehow its throwing error for the line ./fft Module '"node_modules/@xenova/transformers/dist/types/fft"' uses 'export =' and cannot be used with 'export *'.ts(2498) |
Hmm, that's quite strange since that is all done by the typescript compiler (i.e., nothing done by me to do that). I would assume migrating to ES6 syntax would fix it all though. @kungfooman What do you think? |
I by no means intend to hijack this conversation but ES6 just makes sense in the context of this library and it has come up in a few issues by now, I'm all for it. |
Just an update on this. I've spent the day playing around with converting everything to ES6, but there are quite a few issues I've been encountering, especially the way in which non-browser applications would have to mix ES6 and CommonJS imports/exports. It seems a lot easier to support ES6 from CommonJS than it is to support CommonJS from ES6. I'll try a few more things, but considering webpack can be used to handle the conversions for you, it seems logical to stick with CommonJS for now... (unless anyone can get it working flawlessly on their side) As for this issue: #80 (comment), I'll be writing up sample applications over the next few days to make sure everything works as expected. |
@xenova would you have an example of this? It's something I'd really like to see happening and I'm not afraid to get my hands dirty |
Sure, I can publish the branch I was working on: https://github.com/xenova/transformers.js/tree/es6-rewrite. As you'll see, it's quite incomplete (e.g., building with webpack doesn't work) |
Hey, I faced the same issue in my SvelteKit app and managed to work around it by creating a custom TypeScript declaration file. Here's what I did:
This tells the TypeScript compiler that you are defining a module named @xenova/transformers.
Svelte
NextJS (untested)
Let me know if this works for you since our environments are different. I've only tested this in the browser with the getting started example so far. |
@SeanDoc77 About point 5, I hope we use https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/globalThis |
This should now be fixed in the latest version 2.0.0-alpha.0 (https://www.npmjs.com/package/@xenova/transformers). The types are now stored in the types folder and should be automatically detected (due to the types parameter in the package.json). Feel free to reopen or open a new issue if you have any further questions. |
@xenova i am using typescript and we still get this error: Error [ERR_REQUIRE_ESM]: require() of ES Module /Users/jed/travelApp_backend/node_modules/@xenova/transformers/src/transformers.js from /Users/jed/travelApp_backend/src/routes/map/map.route.ts not supported. while importing import { pipeline } from "@xenova/transformers"; |
@jedLahrim Since we don't yet support a CommonJS import, you need to either (1) change your project to e.g., let { pipeline, env } = await import('@xenova/transformers'); |
hhhh you now what i use the await import('@xenova/transformers') like an hour ago and it didnt work now it works im gonna debug it to now why it works now thank you mate |
It is most likely transformed to const TransformersApi = Function('return import("@xenova/transformers")')();
const { pipeline } = await TransformersApi; |
@xenova when im debuging this function:
it throws me the same error:
|
Yep, looks like it's being transformed behind the scenes. Replace it with TransformersApi = Function('return import("@xenova/transformers")')();
const { pipeline } = await TransformersApi; to fix it 👍 |
yeah it worked but we should improve a better solution to get the types ones in types folder with simple import |
Definitely agree. Here's the open feature request for it: #152 |
@xenova bro a way to load a model for text translation directly from file in my local without waiting compiler until download the model then use the .cache after download first time
|
@jedLahrim I'm sorry, I don't quite understand what you mean. Are you saying that the model is cached in |
i mean when u call this function
|
i need to wait some time until the model Xenova/nllb-200-distilled-600M loaded in my node_modules @xenova folder i asked you if there is a function or method to load the Xenova/nllb-200-distilled-600M model uding the path to it example
|
Then yes, you can set the environment variables as follows: import { pipeline, env } from '@xenova/transformers';
// Disable remote models.
env.allowRemoteModels = false;
// Set local model path.
env.localModelPath = '/path/to/local/models/';
// Create pipeline
let translator = await pipeline('translation', 'Xenova/nllb-200-distilled-600M'); Just remember that your model folder must contain |
async _initXenova() { |
That error message should be able to explain what is going wrong. Try removing |
what should i put in my localModelPath |
I can't be 100% certain since I don't know your setup, but either: env.localModelPath = "/Users/jed/Downloads/"; or env.localModelPath = "/Users/jed/Downloads/Xenova/"; or env.localModelPath = "./"; Also, please do not try to spam this issue (which is already closed). If you would like to continue the discussion, feel free to open a new issue. |
yah yah hhhh i have not seen what im importing every things is fine now |
can we load the model from google drive link ? |
Please do not spam this closed issue. If you have questions, please open a new issue. |
Hello, What can I do ? Is it because I'm in a NestJS project ? If using
|
This should be fixable by just defining the variable with const or let. I can't quite remember why I didn't include it in the original comment. Will edit it. e.g., const TransformersApi = Function('return import("@xenova/transformers")')();
const { pipeline } = await TransformersApi; |
It works thanks. I was wondering if it was some Node magic so I pasted it directly without trying to define it. Thanks :D |
I got error When I try to run this code
Posted here because I used to works fine when I import normally. |
Are you perhaps running in Jest? Might be a duplicate of #57. |
Ah yes you are right. Solved. |
However, when I attempted this, I encountered another issue: the error info is: TypeError: "Invalid host defined options". |
I am trying to look around the functionality and using NextJS with Typescript. I keep getting error
Could not find a declaration file for module '@xenova/transformers'
How to reproduce
Create a nextjs project using typescript and install transformers.js
Expected behavior
Should work as types are already integrated
Environment
The text was updated successfully, but these errors were encountered: