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
but it keeps telling me that the module ./../../config/settings.json doesn't exist.
In the source of runSync, I see that you're passing a require wrapper into the context, but I don't know how to make it resolve relative paths correctly.
The text was updated successfully, but these errors were encountered:
The require() problem is a temporary limitation (I still need to find a decent solution). You can work around it by using fs.readFileSync and JSON.parse.
Because it runs the function at compile time, there's no way for it to use runtime variables like the key argument.
What you can do, currently, is this:
varconfig=atcompile.runSync(function(){varread=require('fs').readFileSync;varsettings=JSON.parse(read('config/settings.json','utf8'));// whitelist some keys, or you can just return the whole thingreturn{foo: settings.foo,bar: setting.bar};});// if you still want the getConfig apiexports.getConfig=function(key){returnconfig[key];}
And this ends up like this:
varconfig={"foo": {"...":"..."},"bar": 7};
If you prefer to not do this, you can create your own transform using static-module, which basically just lets you inline function calls (it's what atcompileify, brfs, etc. use).
I have a function that looks as follows:
but it keeps telling me that the module
./../../config/settings.json
doesn't exist.In the source of runSync, I see that you're passing a
require
wrapper into the context, but I don't know how to make it resolve relative paths correctly.The text was updated successfully, but these errors were encountered: