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

huangapple go评论74阅读模式
英文:

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

问题

Serverpod生成命令抛出"Null check operator used on a null value"错误。

在一个全新的项目上使用serverpod generate命令,并且只添加了以下代码时,我会得到以下错误:

example_endpoint.dart文件中,我在ExampleEndpoint类中添加了以下内容:

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

我在协议文件夹中添加了article.yaml文件,其内容如下:

class: Article
fields:
  title: String

这是从serverpod generate输出的内容:

警告!Windows目前尚不受官方支持。事情可能会按预期工作,也可能不会。

糟糕!这个错误可能是由Serverpod工具的内部问题引起的。如果您能在Github上提交一个问题,我们将不胜感激。请包括下面的堆栈跟踪,并描述触发错误的任何步骤。
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>

我正在使用Windows 11,使用的是Serverpod版本1.1.1。

英文:

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&lt;Article&gt; test(Session session) async{
    return Article(
      title: &#39;Test Title&#39;,
    );
  }

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.&lt;anonymous closure&gt; (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)
&lt;asynchronous suspension&gt;
#10     performGenerate (package:serverpod_cli/src/generator/generator.dart:46:19)
&lt;asynchronous suspension&gt;
#11     _main (file:///C:/Users/dschu/AppData/Local/Pub/Cache/hosted/pub.dev/serverpod_cli-1.1.1/bin/serverpod_cli.dart:221:7)
&lt;asynchronous suspension&gt;
#12     main.&lt;anonymous closure&gt; (file:///C:/Users/dschu/AppData/Local/Pub/Cache/hosted/pub.dev/serverpod_cli-1.1.1/bin/serverpod_cli.dart:36:9)
&lt;asynchronous suspension&gt;
#13     main (file:///C:/Users/dschu/AppData/Local/Pub/Cache/hosted/pub.dev/serverpod_cli-1.1.1/bin/serverpod_cli.dart:33:3)
&lt;asynchronous suspension&gt;

I am on Windows 11 using serverpod version 1.1.1

答案1

得分: 1

这个问题的解决方法是在端点文件的顶部添加一个导入行。如果你的协议文件是 article.yaml,你需要添加 import '../generated/article.dart';

在将来的 serverpod 版本中,你将会在终端中收到一个更具描述性的消息,如github问题中所解释的那样。

英文:

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 &#39;../generated/article.dart&#39;;.

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

huangapple
  • 本文由 发表于 2023年5月29日 05:30:33
  • 转载请务必保留本文链接:https://go.coder-hub.com/76353681.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定