6

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");
}

is there any wrong with configuration? screenshot

Boaz
  • 19,892
  • 8
  • 62
  • 70
jiepeng yan
  • 73
  • 1
  • 1
  • 4
  • Upload a screenshot. It's working fine from my end dart version: 2.3.2 in VSCode – Himel Rana Jun 20 '19 at 10:46
  • Does it run properly if you run `dart main.dart` (being in the file directory)? – Mattia Jun 20 '19 at 18:14
  • I'm getting this error ```Error: Error when reading 'main.dart': No such file or directory``` @Mattia – Ronak Patel Jan 08 '20 at 05:48
  • @Patel123 You might not be in the main.dart directory. – Mattia Jan 08 '20 at 13:53
  • For future readers, note the file in the screenshot is marked with a dot next to its name. This means the file contains unsaved changes. By default, VS Code does not automatically save changes. – Boaz Sep 30 '21 at 08:48
  • Does this answer your question? [Why don't other programs see the changes I made to a file in VS Code until I save those changes?](https://stackoverflow.com/questions/76984829/why-dont-other-programs-see-the-changes-i-made-to-a-file-in-vs-code-until-i-sav) – starball Aug 27 '23 at 06:06

8 Answers8

4

try saving it in your folder it works 100% and name it main

2

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.

live-love
  • 48,840
  • 22
  • 240
  • 204
1
  1. Disable the extension. 2.Then, click on Reload Required. https://i.stack.imgur.com/XTHc6.png
  2. Enable extension.
1
  1. On Visual Studio Click on "View"
  2. Then click on Run
  3. Then on the left top corner see run drop-down menu
  4. select add configuration.
  5. Then a JSON file appears.
  6. Now delete everything and paste the below:
 {    
     "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"
        }
    ] }
  1. Now again go to let hand side top and see beside run there is a play type button.
  2. Just press it and allow permission

  3. Now run the code in the terminal. It will work.

1

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.

0

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.

pythonInRelay
  • 99
  • 1
  • 8
-1

you have to do is just save the file ctrl+s

-1

ctrl + s please. you don't save this file

SerifDogru
  • 11
  • 1
  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Oct 14 '22 at 04:35