#Code not exec when the request takes longer 1 - 10 secs

1 messages · Page 1 of 1 (latest)

fiery condor
#

The code work but, no return response becase the time of the request is very longer

trail vessel
#

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

trail vessel
#

Can you switch to fetch? That might fix your perf issues

fiery condor
trail vessel
#

yes

fiery condor
#

@trail vessel the same thing happens

#

and that the response is already almost instantaneous

trail vessel
#

So the response from /submit-request is instantaneous?

fiery condor
#

I just solved it!

trail vessel
#

How'd u do it if I can ask?

fiery condor
# trail vessel 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

fiery condor
trail vessel
#

sure go ahead

fiery condor
# trail vessel 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.

trail vessel
#

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

fiery condor
fiery condor
trail vessel
#

Got confused with the name of the file then (client.ts)

fiery condor
#

The file is called clients.ts because there I have defined the clients of for example my library, axios, the backend, etc.

trail vessel
#

ah alright

fiery condor
trail vessel
#

Normally it means that you're importing the wrong thing, but from looking at the package what you're doing seems to be correct

fiery condor
trail vessel
#

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

fiery condor
trail vessel
#

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

fiery condor
fiery condor
#

The compilation process does not add it automatically

trail vessel
#

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

fiery condor
fiery condor
trail vessel
#

Well I need to see what you changed not the original code

fiery condor
trail vessel
#

Sorry didn't see you pushed

fiery condor
#

In the repo it is without the exports now but of course if you export it you will not find it.

trail vessel
fiery condor
#

Oh sorry, I'm coming

#

I'm starting astro to see what it tells me, before uploading the cmabios to the repo and npm.

fiery condor
#

Again the same mistake as at the beginning

#

even VSCODE detects me that it is a constructor

trail vessel
#

do import { twi } from "tw-to-css"; instead

fiery condor
#

But I don't think that affects what you say about DymoAPI not being a builder

trail vessel
#

Sorry, "bookstore"? I don't think I understand

fiery condor
trail vessel
#

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.

fiery condor
#

The conversion to esm does not work because it seems to still use CJS

fiery condor
#

Same error even though the require is no longer present.

trail vessel
#

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.

fiery condor
trail vessel
#

yes, the one in this directory

fiery condor
#

Let's see if this will compile and I'll try it out

fiery condor
#

How strange

trail vessel
#

you are using esm to import, right?

#

Like, you're importing from a module?

#

can you share that code with me?

fiery condor
#

You mean how do I use the library client? this?

trail vessel
#

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

fiery condor
#

of course

fiery condor
#

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.

trail vessel
#

Of course you need that

#

If you're running ESM you need type: module

fiery condor
#

Great I'm going to add it and see

fiery condor
trail vessel
#

No, it's backwards compatible

trail vessel
fiery condor
trail vessel
#

?

fiery condor
#

It seems that what I did does not come out

trail vessel
#

<@&1129102257422610512> is there someone who can help assist with this issue? I am not really sure how to further assist.

exotic parcel
trail vessel
#

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

exotic parcel
#

And which of these is best to look at the code in

trail vessel
#

Asked for a minimal repro but I think there's a language barrier going on, he gave me an empty stackblitz project

wild saddle
#

Based on this it looks like DymoAPI is not a constructor function

#

is that expected?

fiery condor
#

Good, yes, I have a library which just in Astro always says that it is NOT a contrusctor.

#

but vscode detect it

fiery condor
wild saddle
#

Yeah looking at the ts file louis linked, it is definitely a constructor

exotic parcel
#

Can you share a repo when trying to use it in astro ?

wild saddle
#

Wow their docs are terrible 😅

fiery condor
wild saddle
#

Not the dymo repo

fiery condor
#

The only thing I use is the import, it has no more.

wild saddle
#

This does not use the new keyword

#

in their docs

fiery condor
#
import DymoAPI from "dymo-api";

const DymoClient = new DymoAPI({
    rootApiKey: import.meta.env.DYMO_API_ROOT_API_KEY as string,
    local: true
});
wild saddle
#

have you tried removing it?

fiery condor
wild saddle
#

And what happens?

fiery condor
# wild saddle

I forgot to add it, right, now I've added it in the documentation.

trail vessel
wild saddle
#

Ahhhh okay

exotic parcel
#

So how would it be used in astro and what error happens?

#

Sorry if asking to repeat yourself

fiery condor
# wild saddle

I don't see on which page of the documentation I have that.

wild saddle
#

Under usage

fiery condor
exotic parcel
#

?

wild saddle
#

If I understand correctly yes, but probly best to wait for them to confirm 😅

fiery condor
wild saddle
#

Well at least I helped with some aspect of it 😛

fiery condor
fiery condor
exotic parcel
#

Can you console log ttypeof dymoAPI ?

fiery condor
exotic parcel
#

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

fiery condor
exotic parcel
#

So if you import it into a file in nextjs and console log you get typeof function

#

But in Astro you get typeof object ?

fiery condor
#

Correct

#

Just in case I am checking

#

When adding the type module in the library in the backend I get this error when executing

exotic parcel
#

That’s just from the library directly?

fiery condor
#

This error that occurs is in the backend because I updated the library in which I defined its type as a module.

exotic parcel
#

That error is correct of course you can’t require in ESM and adding type module to package json makes all files ESM

exotic parcel
#

Somewhere there’s a require

fiery condor
#

I just searched for it in the library and in the backend and nothing.

finite mica
#

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

fiery condor
#

One question, is there a way to run something as soon as Astro server starts?

fiery condor
finite mica
#

One sec

#

There ya go

exotic parcel
#

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 ™️

fiery condor
#

I can't see if it works because I get this error and I'm not using it in my project that string

exotic parcel
#

Mmm

fiery condor
exotic parcel
#

This is during dev server? And you don’t use astro-icon at all?

fiery condor
exotic parcel
#

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?

fiery condor
fiery condor
#

Now it's working, but I've had other times it's like random from the runtime.

exotic parcel
#

Are you doing stuff with the dev server via an integration ?

fiery condor
exotic parcel
#

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

fiery condor
#

I am trying to run a func right after starting the server.

exotic parcel
#

Hmm and that file doesn’t touch any .astro stuff does it?

fiery condor
#

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.

finite mica
fiery condor
#

Does anyone know about this error in Astro?
It started happening out of nowhere

#

(on restarting it disappeared)

#

but he showed up again

fiery condor
#

It keeps coming up more and more and it is very annoying.