Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[windows only] Require fails to load native addons with path longer than 260 characters #2964

Closed
justinmchase opened this issue Sep 19, 2015 · 11 comments
Labels
module Issues and PRs related to the module subsystem. windows Issues and PRs related to the Windows platform.

Comments

@justinmchase
Copy link

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?

@mscdex mscdex added module Issues and PRs related to the module subsystem. windows Issues and PRs related to the Windows platform. labels Sep 19, 2015
@mscdex
Copy link
Contributor

mscdex commented Sep 19, 2015

It's probably best to keep with how long paths are handled for non-addons (e.g. use path._makeLong() on the path). Maybe something like (untested)?:

Module._extensions['.node'] = function (module, filename) {
  return process.dlopen(module, path._makeLong(filename));
};

@justinmchase
Copy link
Author

@mscdex Oh beautiful 😄 I didn't know about that function. That does appear to do what I need.

@seishun
Copy link
Contributor

seishun commented Oct 15, 2015

Isn't this fixed by #2965?

@justinmchase
Copy link
Author

Yup, forgot to come back and close this. Thanks.

@MattiooFR
Copy link

Hi, I'm having the same issue and I can't manage to fix it ...
I developped a native module with node v4, but now I'm changing my computer to a new one, and impossible to use this module. I can compile, everything seems to be installed (VS 2013, python etc..)

When I try to launch a basic node index.js it says that :

{ node-mod } master » node index.js                       
module.js:460
  return process.dlopen(module, path._makeLong(filename));
                 ^

Error: Le module spécifié est introuvable. (translation "Error : The specified module is not found")
\\?\C:\PROJET\node-mod\build\Release\mod.node
    at Error (native)
    at Object.Module._extensions..node (module.js:460:18)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:311:12)
    at Module.require (module.js:366:17)
    at require (module.js:385:17)
    at Object.<anonymous> (C:\PROJET\node-mod\index.js:1:74)
    at Module._compile (module.js:435:26)
    at Object.Module._extensions..js (module.js:442:10)
    at Module.load (module.js:356:32)

In the index.js it's only the var module = require('./build/Release/mod')()

If you have any ideas... I'm stuck in this since 2 days ><

@thefourtheye
Copy link
Contributor

@MattiooFR Which version are you using? The proposed fix landed in v4.2.0 only

@MattiooFR
Copy link

@thefourtheye Node v4.2.1 64 bit

@thefourtheye
Copy link
Contributor

If you don't mind can you please translate

Error: Le module spécifié est introuvable.

@MattiooFR
Copy link

Oh for sure ! @thefourtheye

Error : The specified module is not found

What's weird is that it's fully working on my other computer, I just copy the folder, I don't try to recompile, and with the new one when I try to node index.js it says that error.
My path does not even seems long

EDIT :

OK, my bad, some drivers were missing, now everything works 👍

@justinmchase
Copy link
Author

For future reference, this error can occur when loading a module that has dependencies on other modules that are not found. On windows you can use this tool to look at your dependencies and see which is not loading properly:

http://dependencywalker.com/

@bmeck
Copy link
Member

bmeck commented Nov 12, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
module Issues and PRs related to the module subsystem. windows Issues and PRs related to the Windows platform.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants