hi!
I want to be able to use some common variables and functions within a template helper script file, but I get :
ReferenceError: [var/function] is not defined
yes, this is because in the first case you tried to serialize the helperFoo and put it inside req.template.helpers, this gives you error because when you serialize the function you lost access to any variable outside the function, so the _commonDataForAllHelpers variable can not be found when helperFoo runs. this is basically how javascript works with functions getting serialized and the revived, the function is no longer a closure and lost access to other variables outside its definition.
Something like this maybe?
your second case works ok, you just have a small typo here '\n' +\n{#asset ./helpers_src_asset.js}it should be'\n' + \n{#asset ./helpers_asset.js}, you can use that approach or just enable the shared helpers check of the asset which basically does the same.