dartdart-pub

Missing the required "name" field


Is there a way that dart pub creates a pubspec.yaml to install the CSV module?

$ dart pub add csv
Could not find a file named "pubspec.yaml" in "/home/michal/Downloads/shazam".
$ touch pubspec.yaml
$ dart pub add csv
Error on line 1, column 1 of pubspec.yaml: Missing the required "name" field.

Solution

  • For dart pub add command to work you must need a pubspec.yaml file in the current directory. The pubspec.yaml file keeps track of the dependencies and other related information about your Flutter/Dart project.

    By said that, I want to clarify that the pubspec.yaml file will be auto-generated from the very beginning of the project. The file will be generated when you start project by running either:

    dart create <project_name>
    

    Or

    flutter create <project_name>
    

    So you don't manually have to create the file. Anyway, if you want to manually create the file make sure it contains name, and enviornment properties in it.

    name: <your_project_name>
    
    environment:
      sdk: ">=3.0.0"
    

    Check this article for detailed overview of the pubspec.yaml file: https://dart.dev/tools/pub/pubspec.