英文:
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<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
答案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 '../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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论