#Code not exec when the request takes longer 1 - 10 secs
1 messages · Page 1 of 1 (latest)
Alright, so to start off:
It's generally recommended to use fetch since that's included with Nodejs and thus is a lot faster
Axios is known to have performance problems
YEah I'm using axios
Can you switch to fetch? That might fix your perf issues
From axios to fetch?
yes
give me a moment and I'll try
@trail vessel the same thing happens
and that the response is already almost instantaneous
So the response from /submit-request is instantaneous?
I just solved it!
How'd u do it if I can ask?
After reducing the response time with a different type of confirmation, I was optimizing some settings of the Axios fetch and then I also put the Promise<Response> typing that I missed and well it works without problem now
Although I have another problem, I don't know if you could help me
sure go ahead
I have a library that allows users to query the API through it, in a faster, better and easier way, it works everywhere, but in astro it gives a very strange error, see
Also in my Astro App (independent of the library) it shows me this error and looking at the code I can't find the reason why and of course the error doesn't specify anything.
If you're doing that on the client I recommend you stop doing so, if you call this in a client script you'd be leaking a secret
That's most likely also the reason for the error, the Package might rely on Node.js functionality which is not available in the browser
It is not client-side, it is server-side.
The file does not run in the browser
Got confused with the name of the file then (client.ts)
The file is called clients.ts because there I have defined the clients of for example my library, axios, the backend, etc.
ah alright
It is rare for Astro to say that a builder is not one
Normally it means that you're importing the wrong thing, but from looking at the package what you're doing seems to be correct
Yeah that's why it is rare and works correctly everywhere, except in projects using Astro
Found the issue, it's with the package itself. You've got the same file in the cjs export and the esm export, which won't work since esm uses a different syntax
Which is why it works fine when using require() but not with import
I'm going to check, I'm having a hard time with CJS/ESM, what should I adapt in the library?
Line 280 and line 281 have to go
Your build process will add them automatically for you
Long story short - don't use module.exports with typescript
I'll try deleting it then and see if it works.
The compilation process does not add it automatically
Okay so your problem lies somewhere with your build process and how you compile your types, I'm not an expert on that so I cannot help you here. It is not an Astro problem
If you can share the code with me I might be able to help, error screenshots might not really help here
Would you know of anyone who can help me with this?
https://github.com/TPEOficial/dymo-api-node this is the repo
Well I need to see what you changed not the original code
What do you mean?
Sorry didn't see you pushed
In the repo it is without the exports now but of course if you export it you will not find it.
Right here, "export default DymoAPI" was right, you only needed to remove 280 and 281
Oh sorry, I'm coming
I'm starting astro to see what it tells me, before uploading the cmabios to the repo and npm.
I think I know why give me 2 minutes.
Again the same mistake as at the beginning
even VSCODE detects me that it is a constructor
Okay, we've got a different issue now:
You cannot require and import in the same file.
https://github.com/TPEOficial/dymo-api-node/blob/aa3ceab36d13b156ac2a3a4a5d32390bc38ba925/src/branches/private.ts#L5
Right here you use require which ends up leading to the issue you're facing
do import { twi } from "tw-to-css"; instead
The bookstore does not accept other types of imports for some reason.
But I don't think that affects what you say about DymoAPI not being a builder
Sorry, "bookstore"? I don't think I understand
https://www.npmjs.com/package/tw-to-css?activeTab=readme#usage
Here it says you can use imports
I will check, it is normal that both ESM and CJS in the builds both are exported with exports.default = DymoAPI;.
No, only CJS will with with that. ESM requires you to do export DymoAPI. If you're trying to use "import" in a commonjs file, that won't work, you need to use require. If you're trying to use commonjs with Astro, that WILL NOT WORK. It is only designed to work with ESM.
The conversion to esm does not work because it seems to still use CJS
Ya usa export now I'm going to see about twi
Same error even though the require is no longer present.
Something else that might be causing issues:
in your root directory you have an index.ts file, delete that. You're defining your exports via your package.json file, the index.ts file at the root doesn't have to be there.
I understand, I'm coming, just the index.ts?
yes, the one in this directory
Let's see if this will compile and I'll try it out
you are using esm to import, right?
Like, you're importing from a module?
can you share that code with me?
You mean how do I use the library client? this?
Okay I cannot help more without a reproduction, if you can make one via https://astro.new/minimal that'd be great. I've got stuff to work on, ping me once you've got it working/crashing in a minimal environment
of course
The only thing I can think of is to put it as a type module in the package.json but I don't know if that affects CJS.
Great I'm going to add it and see
does it affect CJS users?
No, it's backwards compatible
Also, you sent me an empty reproduction, I need one with an example of the code you're using in it.
An empty playback? complete it with the code
?
It seems that what I did does not come out
<@&1129102257422610512> is there someone who can help assist with this issue? I am not really sure how to further assist.
Very long threads there anyway we can get a recap? @fiery condor
Basically:
Vite import issues, tracked it down to wrong build process, now trying to figure out why (what looks correct to me) isn't working in a vite env
And which of these is best to look at the code in
Asked for a minimal repro but I think there's a language barrier going on, he gave me an empty stackblitz project
https://www.npmjs.com/package/dymo-api - The package they're maintaining
https://github.com/TPEOficial/dymo-api-node - Related GitHub repo
https://github.com/TPEOficial/dymo-api-node/blob/main/src/dymo-api.ts - File that's causing the issue (see reply)
Good, yes, I have a library which just in Astro always says that it is NOT a contrusctor.
but vscode detect it
DymoAPI if it is a builder
Yeah looking at the ts file louis linked, it is definitely a constructor
Can you share a repo when trying to use it in astro ?
Wow their docs are terrible 😅
This is the lib repo https://github.com/TPEOficial/dymo-api-node
The project for where you are trying to use it
Not the dymo repo
The only thing I use is the import, it has no more.
import DymoAPI from "dymo-api";
const DymoClient = new DymoAPI({
rootApiKey: import.meta.env.DYMO_API_ROOT_API_KEY as string,
local: true
});
have you tried removing it?
Yeah
And what happens?
I forgot to add it, right, now I've added it in the documentation.
He's the maintainer of the package
Ahhhh okay
So how would it be used in astro and what error happens?
Sorry if asking to repeat yourself
I don't see on which page of the documentation I have that.
This is the same as for the rest of the projects, in fact in the rest of the projects it works correctly.
So
import DymoAPI from "dymo-api";
const DymoClient = new DymoAPI({
rootApiKey: import.meta.env.DYMO_API_ROOT_API_KEY as string,
local: true
});
Results in :
?
If I understand correctly yes, but probly best to wait for them to confirm 😅
The new version is being uploaded, adding the new that was missing in some pages.
Well at least I helped with some aspect of it 😛
In my case that I have the api in local I must define local true to be able to use localhost and be faster, but yes
YES! thank you
Can you console log ttypeof dymoAPI ?
That's what I was going to tell you, I did it before and it came out as an object type
Ok and you’re sure you’re importing it properly ? I.e it’s named if it should be etc
there’s nothing really special about how Astro does imports
So if it’s not a function in astro it shouldn’t be a function in another framework
But I could be wrong
Yes yes, in fact we have it in other projects that we don't use astro like the backend or a project with nextjs and it doesn't give us any problem
So if you import it into a file in nextjs and console log you get typeof function
But in Astro you get typeof object ?
Correct
Just in case I am checking
When adding the type module in the library in the backend I get this error when executing
That’s just from the library directly?
This error that occurs is in the backend because I updated the library in which I defined its type as a module.
That error is correct of course you can’t require in ESM and adding type module to package json makes all files ESM
I am not requiring it
Somewhere there’s a require
I just searched for it in the library and in the backend and nothing.
https://thesametech.com/how-to-build-typescript-project/ I will try to follow these steps
This guide is good too
If you don’t need to build
For ESM and CJS. I would suggest not
Doing it. I would suggest building
Only for ESM.
But if you want to support both. Use tsup
One question, is there a way to run something as soon as Astro server starts?
Do you know where I should put that?
One sec
There ya go
I think @fiery condor wanted it in prod
Server:start is for an astro integration being able to do stuff when dev server starts
At least I’m pretty sure 😅
Could be wrong ™️
I can't see if it works because I get this error and I'm not using it in my project that string
Mmm
It's quite rare because I don't use that group of icons.
This is during dev server? And you don’t use astro-icon at all?
I do use astro-icon but not anything that has that group or icon name, it is in dev mode.
That is the virtual module astro icon creates so you can import basically it means it hasn’t been set up properly
No idea how that would happen though
Can you share a repo?
I will do some astro checks and install the library to see if it will work.
The problem is that this repo is privately owned by the company.
Now it's working, but I've had other times it's like random from the runtime.
Are you doing stuff with the dev server via an integration ?
What kind of things do you mean?
i don’t know just wondering if this errror just started happening after trying server:start
Thinking maybe there’s a way you’re accessing something too early in the pipeline but I’m just shooting in the dark
I am trying to run a func right after starting the server.
Hmm and that file doesn’t touch any .astro stuff does it?
I just deleted it anyway, the astro icons error is something punctual, when restarting npm run dev sometimes it appears and sometimes not, most of the time it doesn't appear.
Not
Fully
Sure either! The docs aren’t quite clear on that.
Does anyone know about this error in Astro?
It started happening out of nowhere
(on restarting it disappeared)
but he showed up again
It keeps coming up more and more and it is very annoying.