I just run this code in VsCode and show this problem
Dart_LoadScriptFromKernel: The binary program does not contain 'main'.
Dart version:2.3.2
void main() {
print("hello");
}
I just run this code in VsCode and show this problem
Dart_LoadScriptFromKernel: The binary program does not contain 'main'.
Dart version:2.3.2
void main() {
print("hello");
}
In Visual Studio Code, this error happens when you are trying to run your main.dart file, but you have another window (or tab) open with a class file for example. Make sure when you run your code you have the main (main.dart) tab open with your main function in it.
{
"version": "0.2.0",
"configurations": [
{
"name": "Dart: Attach to Process",
"type": "dart",
"request": "attach"
},
{
"name": "Dart",
"type": "dart",
"request": "launch",
"program": "bin/main.dart"
},
{
"name": "Dart: Run all Tests",
"type": "dart",
"request": "launch",
"program": "./test/"
},
{
"name": "Dart: Attach to Process",
"type": "dart",
"request": "attach"
},
{
"name": "Dart",
"program": "bin/main.dart",
"request": "launch",
"type": "dart"
}
] }
Just press it and allow permission
Now run the code in the terminal. It will work.
I also faced the same problem. Then I found that I did not save the file (code). Then I save it (ctrl+s or File > Save). Finally I run the command
dart hello.dart
and get the expected output.
VScode always requires a main.dart
file in the project directory with at least the minimum contents:
void main() {}
With that file present, you can then name any other file you're working on, and execute it directly from the VScode console using eg. dart hello_world.dart
(with example contents):
void main() {
print("Hello World");
}
and the main.dart
file does not need to be open when this is done.
you have to do is just save the file ctrl+s
ctrl + s please. you don't save this file