Description
I'm having trouble where somewhere down the line a dependency of mine is attempting to load a native addon. Due to deep nesting the process of requiring this addon fails with the error "The filename or extension is too long".
However, I found that I am able to work around this by modifying the global Module
to always prepend "\\\\?\\"
to paths when attempting to load native addons.
This works because paths with that funky prefix kicks win32 path handling into extended-length path mode, according to MSDN:
https://msdn.microsoft.com/en-us/library/windows/desktop/aa365247(v=vs.85).aspx#short_vs._long_names
To specify an extended-length path, use the "\?" prefix. For example, "\?\D:\very long path".
My workaround looks like this basically:
var os = require('os');
if (os.platform() == 'win32') {
var prefix = "\\\\?\\";
var Module = require('module');
Module._extensions['.node'] = function (module, modulePath) {
if (modulePath.indexOf(prefix) !== 0) {
modulePath = prefix + modulePath;
}
return process.dlopen(module, modulePath);
}
}
It appears to allow me to successfully load any native addon now, regardless of path length. I'm thinking of submitting a PR which would patch lib/module.js#L355 to essentially have this same functionality.
What do you think? Are there any gotcha's or can anyone think of a reason why this wouldn't work in the general case?