I couldn't find any answers on importing JSON files with the new ES modules implementation, all the answers that I've found on StackOverflow are for code that's transpiled using Babel, I want to import my package.json
file:
import pkg from '../package.json';
And I'm getting this error:
(node:7863) ExperimentalWarning: The ESM module loader is experimental.
internal/modules/run_main.js:54
internalBinding('errors').triggerUncaughtException(
^
TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension ".json" for /home/user/files/project/package.json imported from /home/user/files/project/version.js
at Loader.resolve [as _resolve] (internal/modules/esm/default_resolve.js:126:13)
at Loader.resolve (internal/modules/esm/loader.js:72:33)
at Loader.getModuleJob (internal/modules/esm/loader.js:156:40)
at ModuleWrap.<anonymous> (internal/modules/esm/module_job.js:42:40)
at link (internal/modules/esm/module_job.js:41:36) {
code: 'ERR_UNKNOWN_FILE_EXTENSION'
}
I'm using the latest Node.js 13.6.0, am I only left with the option to read the file using the fs
module?