Trying to do a migration to esm I’ve stumbled upon strange behavior where using import to load json file behaves somehow different from require.
Following code:
const jsonRequire = require(somePath);
const jsonImport = await import(somePath);
console.error(jsonRequire);
console.error(jsonImport);
Produces this output:
{
'$schema': 'http://json-schema.org/draft-07/schema#',
type: 'object',
additionalProperties: false,
}
{
'$schema': [Getter],
type: [Getter],
additionalProperties: [Getter],
}
Which gives an error when consumed by another library.
- What is the difference between this two?
- Why one logged as value while another as
[Getter]
. - How to reproduce require behavior using import?