Having strange compiler issue with [async] and await

I created a new unit to contain a few classes for my WEB Core app. I've got several already. When I added it to one of my apps to start some testing, it started giving me compiler errors like this:

[Error] uScanManager.pas(243): await only available in async procedure

for EVERY single method that is tagged with [async] in front of it.

I've got dozens of similar methods, both procedures and functions, in other units, and they all compile and run fine.

This one has seemingly decided to refuse to allow the use of [async] on any of the methods!

I mean ... the compiler error is just plain WRONG! It's referring to lines that look like this:

str := await( myobj.DoThis( 'abcdef' ) );

INSIDE of methods that HAVE the [async] tag in front of them. I comment one out, and the next one shows up. When they're all commented out, I get no errors. Nothing will compile with await used anywhere!

Again, ALL of the methods with these errors DO HAVE [async] in front of their declarations!

I'm wondering if anybody else has run into that and what might be the cause.

I suspect there's a strange typo somewhere, or maybe it's an issue with ording in a uses clause. But I've got several smallish units just like this that implement different things and there's just not that much to go wrong.

WOW ... it turns out the problem was somehow caused because I had the unit in a folder with other common units, and the folder was added to the library search path. When I explicitly added the unit to the project, it compiles just fine.

I've run into this before, but not as strange.

So I guess the moral of the story is ... don't rely on using the library search path to find units, but rather add them to the project explicitly.

Is this a bug or known problem with the pas2js compiler or something else?

The [async] attribute is a TMS WEB Core specific language feature.
It requires that the units using it are part of the project for proper compilation.

hmmm ... I never realized that. Thanks.

I just ran into the very same issue.
Like David, I decided to put certain classes into their own units to be re-used by multiple WebCore projects. As long as they are added directly to the project, it all compiles and works fine.

As soon as I try to use these units like a "custom code library", by adding the directory they live in to "Project/Options/Search Path" (for LSP) and to "Project/Options/TMSWeb Search Path" (for pas2js) I get these await only available in async procedure errors like David got.

I realize that @brunofierens said they need to be part of the project, but quite frankly, I don't understand the reasoning. Why are "my" utility units different from those TMS ships in the box? Don't TMS utility units use await() anywhere? Isn't there a way to have your own "utility library" for WebCore that can just be used by adding the required units to your uses clauses?

The work around works, but it's still somehow counter intuitive...

We will check what we can do.
Reason is that Delphi LSP doesn't understand the async decorator and we therefore introduced the [async] attribute to keep the LSP happy and postprocess it to make it an async decorator for all units in the project.
You could also use the async decorator instead in your units.