Back

[SOLVED] Import issues

  • 0
  • Functions
darShan
24 Aug, 2023, 12:49

Locally when I run the built up function (main.dart), I can import everything just fine. However the imports do not work if I push the code.tar.gz to deployment.

Here are the logs from build:

TypeScript
Info: Compiling with sound null safety
user_code/lib/main.dart:1:8: Error: Error when reading 'user_code/lib/utils/model/response.dart': No such file or directory
import 'utils/model/response.dart';
       ^
user_code/lib/main.dart:2:8: Error: Error when reading 'user_code/lib/utils/network.dart': No such file or directory
import 'utils/network.dart';
       ^
user_code/lib/main.dart:16:28: Error: Undefined name 'NetworkResponse'.
    Network.send(response);
                           ^^^^^^^^^^^^^^^
user_code/lib/main.dart:16:5: Error: Undefined name 'Network'.
    Network.send(response);
    ^^^^^^^
Error: AOT compilation failed

Short snipped from the main.dart:

TypeScript
import 'utils/network.dart';
import 'utils/model/response.dart';

Future<void> start(final request, final response) async {
  final variables = request.variables;
  final apiKey = variables['REMOTE_CONFIG_API_KEY'].toString();
  final event = variables['APPWRITE_FUNCTION_EVENT'].toString();

  // make network requests and send results back with response.send()
}
TL;DR
The user is experiencing import issues with their Dart project. They tried using the `project:*/*` format for imports, which worked. They also mentioned that using relative imports instead of absolute imports may be a solution. Additionally, they mentioned that they were able to run the project locally with no issues, but the imports failed when they pushed the `code.tar.gz` to deployment. The error message indicates that the files `response.dart` and `network.dart` cannot be found. Solution: 1. Try using the `project:*/*` format for imports. 2. Consider using relative imports instead of absolute imports. 3. Double
D5
24 Aug, 2023, 12:50

How you're deploying the function?

darShan
24 Aug, 2023, 12:51

manually uploading the code.tar.gz

D5
24 Aug, 2023, 12:55

Could you please try deploying using cli?

D5
24 Aug, 2023, 12:55

I had some similar errors, and solved it by creating a folder and function with CLI and deploying with it too

darShan
24 Aug, 2023, 12:56

I'll try.

darShan
24 Aug, 2023, 13:02

Failed with same stacktrace.

darShan
24 Aug, 2023, 13:20

Added the whole implementation inside main.dart & it works.

D5
24 Aug, 2023, 15:27

Uh, what do you mean?

darShan
24 Aug, 2023, 18:42

I had 3 files in total, main.dart, utils/response.dart, utils/network.dart. I used all the logic of 3 separate files inside main.dart without any imports to external files which seems to work.

Drake
25 Aug, 2023, 17:07

Maybe use relative imports instead?

Otherwise, you can have a pubspec.yaml and give your package a name

darShan
26 Aug, 2023, 05:40

hmm, this completely skipped my mind. Tried the project:*/* format import by moving the logger.dart in lib folder & did import 'package:import_issues/logger.dart'; which worked! 🤩

darShan
26 Aug, 2023, 05:42

I'll add this info. on the GitHub issue as well, this probably needs to be documented somewhere also I guess. Maybe I've been completely off dart for quite sometime as well, hence this issue lol.

darShan
27 Aug, 2023, 05:46

This can be marked as SOLVED.

D5
27 Aug, 2023, 10:14

[SOLVED] Import issues

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