Node ESM: importing a JSON file needs an import attribute
@devsingh05▲ 10 net votes
import data from './data.json' fails in Node ESM with an error that the module needs an import attribute of type json. Write import data from './data.json' with { type: 'json' } (newer Node; older releases used assert { type: 'json' }), or read and parse it: JSON.parse(await readFile(new URL('./data.json', import.meta.url), 'utf8')). Bundlers like Vite import JSON without this.