Back

[SOLVED] Function compilation error Dart 3.1

  • 0
  • Functions
  • Flutter
Disk_MTH
19 Nov, 2023, 21:57

I have an error compiling a cloud function with Dart 3.1

Here is some information :

Function is in auto-deploy from Github on a self-hosted instance

".env" has these two lines and Dart 3.1 is correctly detected _APP_FUNCTIONS_RUNTIMES=node-16.0,php-8.0,python-3.9,ruby-3.0,dart-3.1 _APP_FUNCTIONS_ENVS=node-16.0,php-7.4,python-3.9,ruby-3.0,dart-3.1

here is my "pubspec.yaml"

TypeScript
name: starter_template
version: 1.0.0

environment:
  sdk: ^3.1.0

dependencies:
  dart_appwrite: ^10.0.0

dev_dependencies:
  lints: ^3.0.0

here is my dart code in "lib/main.dart" code

TypeScript
import "dart:async";
import "dart:io";
import "package:dart_appwrite/dart_appwrite.dart";

Future<dynamic> main(final context) async {
  final Map<String, String> envVars = Platform.environment;
  final client = Client()
      .setEndpoint("https://backend.diskmth.fr/v1")
      .setProject(envVars["APPWRITE_FUNCTION_PROJECT_ID"])
      .setKey(envVars["APPWRITE_API_KEY"]);
  
  context.log("Hello, Logs!");
  context.log(envVars);
  
  context.error("Hello, Errors!");
  
  if (context.req.method == "GET") {
    return context.res.send("Hello, World!");
  }
  
  return context.res.json({
    "motto": "Build like a team of hundreds_",
    "learn": "https://appwrite.io/docs",
    "connect": "https://appwrite.io/discord",
    "getInspired": "https://builtwith.appwrite.io",
  });
}

and finally here is the error I get during the deployement

TypeScript
Docker Error: Preparing for build ...
Resolving dependencies...
+ async 2.11.0
+ boolean_selector 2.1.1
+ collection 1.18.0
+ matcher 0.12.16
+ meta 1.11.0
+ path 1.8.3
+ pub_semver 2.1.4
+ pubspec 2.3.0
+ quiver 3.2.1
+ source_span 1.10.0
+ stack_trace 1.11.1
+ stream_channel 2.1.2
+ string_scanner 1.2.0
+ term_glyph 1.2.1
+ test_api 0.6.1
+ uri 1.0.0
+ yaml 3.1.2
Changed 17 dependencies!
found user package starter_template
added user package as dependency to server.
Updated server import of user code
Building ...
Resolving dependencies...
+ async 2.11.0
+ collection 1.18.0
+ dart_appwrite 10.0.0
+ http 1.0.0 (1.1.0 available)
+ http_parser 4.0.2
+ meta 1.11.0
+ path 1.8.3
+ shelf 1.4.1
+ source_span 1.10.0
+ stack_trace 1.11.1
+ starter_template 1.0.0 from path /usr/local/build
+ stream_channel 2.1.2
+ string_scanner 1.2.0
+ term_glyph 1.2.1
+ typed_data 1.3.2
Changed 15 dependencies!
Compiling ...
src/server.dart:5:8: Error: Error when reading '../build/lib/lin/main.dart': No such file or directory
import 'package:starter_template/lin/main.dart' as user_code;
       ^
src/server.dart:115:25: Error: Method not found: 'main'.
              user_code.main(context)
                        ^^^^
src/server.dart:125:38: Error: Method not found: 'main'.
            output = await user_code.main(context);
                                     ^^^^
Error: AOT compilation failed
Generating AOT kernel dill failed!

If you have any ideas as to why I'm getting this error, I'd love some help.

Thanks in advance

TL;DR
Title: [SOLVED] Function compilation error Dart 3.1 - User is experiencing a function compilation error when deploying a Dart function. - They provide their folder structure, pubspec.yaml file, and code. - They receive the error message: "No such file or directory" and "Method not found: 'main'" during the compilation process. - The issue is caused by a typo in the entrypoint specified in the pubspec.yaml file. - Solution: Correct the entrypoint path in the pubspec.yaml file to "lib/main.dart" and redeploy the function.
Drake
19 Nov, 2023, 21:59

What's your folder structure and what are the function root and entrypoint options for your function?

Disk_MTH
19 Nov, 2023, 22:02

The root is the root of my repo branch and my entry point is lib/main.dart

Disk_MTH
19 Nov, 2023, 22:02

And my branch looks like this :

Disk_MTH
19 Nov, 2023, 22:03

Discord

Drake
19 Nov, 2023, 22:03

Would you please share a screenshot?

Disk_MTH
19 Nov, 2023, 22:05

Yep

Disk_MTH
19 Nov, 2023, 22:07

Discord

Drake
19 Nov, 2023, 22:11

You have a typo in your entrypoint

Disk_MTH
19 Nov, 2023, 22:35

Oh f***, my bad I'll correct tomorrow and closed the ticket if it's good. If it's just this, sorry for the time waste πŸ₯Ί

Drake
19 Nov, 2023, 22:53

No worries!

Disk_MTH
20 Nov, 2023, 08:08

Ok the function deploy now works thanks πŸ‘

Disk_MTH
20 Nov, 2023, 08:08

[SOLVED] Function compilation error Dart 3.1

Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more