TypeError: yaml.safeload is not a function

I have this error when i run the gulp file 

var gulp = require("gulp");
var yaml = require("js-yaml");
var path = require("path");
var fs = require("fs");
//converts yaml to js
gulp.task("swagger", function() {
var doc = yaml.safeload(fs.readFileSync(path.join(__dirname, "api/swagger/swagger.yaml")));
fs.writeFileSync(
path.join(__dirname, "../golang.json"),
JSON.stringifty(doc, null," ")
);
});
//watch for changers
gulp.task("watch", function() {
gulp.watch("api/swagger/swagger.yaml", ["swagger"]);
})

Answers 2

  • import.js/fs.readFile

    fs.readFile(fileName, 'utf8', function(err, data){
     if(err){
      return console.log(err);
     }
    
     // Turn string from file to an Array
     if (fileName.endsWith('yaml') || fileName.endsWith('yml')) {
      dataArray = YAML.safeLoad(data);
     } else {
      dataArray = JSON.parse(data);
     }
    
     udpateCollection(dataArray);
    
    })
    
    
    
    Brilliant job! This is truly above and beyond.
    Great work buddy...Keep doing good work 
    From
    <a href=" https://www.mylifemyroad.com " rel="nofollow noopener"> Besties Article
    


Related Articles