You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have been able to import json files using require("myfile.json");. I have some files that are actually json but are named with a different file extension (myfile.jlib for example). How can I require them as normal json without changing the filename?
I'm not aware of a replacement for the CommonJS module loader (require()) other than to read the file in with something like fs.readFile() and calling JSON.parse() on the results.
Activity
richardlau commentedon Apr 8, 2019
The deprecated way is to use
require.extensions.I'm not aware of a replacement for the CommonJS module loader (
require()) other than to read the file in with something likefs.readFile()and callingJSON.parse()on the results.For ECMAScript modules (esm) the replacement seems to be to use loader hooks.
cc @nodejs/modules