custom-module: loadJSON: ignore BOM

This commit is contained in:
jean-emmanuel 2022-01-13 01:14:34 +01:00
parent 6e6c0adc56
commit 0412ba2c28

View file

@ -28,7 +28,9 @@ class CustomModule {
if (url.split('.').pop() === 'json') {
try {
url = path.resolve(path.dirname(this.filename), url)
return JSON.parse(fs.readFileSync(url, 'utf8'))
var content = fs.readFileSync(url, 'utf8')
if (content[0] === '\ufeff') content = content.slice(1) // remove BOM
return JSON.parse(content)
} catch(e) {
console.error('(ERROR) could not load json file from ' + url)
console.error(e.message)