dartserverpod

What causes 'Null check operator used on a null value' error while using serverpod generate command in Dart on Windows 11?


Serverpod generate command throws "Null check operator used on a null value" error.

While using serverpod generate on a brand-new project with only the following code added, I get the following error:

In example_endpoint.dart, I added this in the ExampleEndpoint class:

  Future<Article> test(Session session) async{
    return Article(
      title: 'Test Title',
    );
  }

I added article.yaml in the protocol folder with the following content:

class: Article
fields:
  title: String

This is the output from serverpod generate:

WARNING! Windows is not officially supported yet. Things may or may not work as expected.

Yikes! It is possible that this error is caused by an internal issue with the Serverpod tooling. We would appreciate if you filed an issue over at Github. Please include the stack trace below and describe any steps you did to trigger the error.
https://github.com/serverpod/serverpod/issues
Null check operator used on a null value
#0      new TypeDefinition.fromDartType (package:serverpod_cli/src/generator/types.dart:75:49)
#1      new TypeDefinition.fromDartType.<anonymous closure> (package:serverpod_cli/src/generator/types.dart:70:56)
#2      MappedListIterable.elementAt (dart:_internal/iterable.dart:415:31)
#3      ListIterator.moveNext (dart:_internal/iterable.dart:344:26)
#4      new _GrowableList._ofEfficientLengthIterable (dart:core-patch/growable_array.dart:189:27)
#5      new _GrowableList.of (dart:core-patch/growable_array.dart:150:28)
#6      new List.of (dart:core-patch/array_patch.dart:47:28)
#7      ListIterable.toList (dart:_internal/iterable.dart:214:7)
#8      new TypeDefinition.fromDartType (package:serverpod_cli/src/generator/types.dart:70:73)
#9      EndpointsAnalyzer.analyze (package:serverpod_cli/src/analyzer/dart/endpoints_analyzer.dart:168:48)
<asynchronous suspension>
#10     performGenerate (package:serverpod_cli/src/generator/generator.dart:46:19)
<asynchronous suspension>
#11     _main (file:///C:/Users/dschu/AppData/Local/Pub/Cache/hosted/pub.dev/serverpod_cli-1.1.1/bin/serverpod_cli.dart:221:7)
<asynchronous suspension>
#12     main.<anonymous closure> (file:///C:/Users/dschu/AppData/Local/Pub/Cache/hosted/pub.dev/serverpod_cli-1.1.1/bin/serverpod_cli.dart:36:9)
<asynchronous suspension>
#13     main (file:///C:/Users/dschu/AppData/Local/Pub/Cache/hosted/pub.dev/serverpod_cli-1.1.1/bin/serverpod_cli.dart:33:3)
<asynchronous suspension>

I am on Windows 11 using serverpod version 1.1.1


Solution

  • The solution to this problem is to add an import line at the top of endpoint file. If your protocol file was article.yaml you will need to add import '../generated/article.dart';.

    In a future release of serverpod you will get a more descriptive message in the terminal as explained in the github issue.