Title: [windows only] Require fails to load native addons with path longer than 260 characters · Issue #2964 · nodejs/node · GitHub
Open Graph Title: [windows only] Require fails to load native addons with path longer than 260 characters · Issue #2964 · nodejs/node
X Title: [windows only] Require fails to load native addons with path longer than 260 characters · Issue #2964 · nodejs/node
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 ...
Open Graph 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 filenam...
X 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 "Th...
Opengraph URL: https://github.com/nodejs/node/issues/2964
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"[windows only] Require fails to load native addons with path longer than 260 characters","articleBody":"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\".\n\nHowever, 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.\n\nThis works because paths with that funky prefix kicks win32 path handling into extended-length path mode, according to MSDN:\nhttps://msdn.microsoft.com/en-us/library/windows/desktop/aa365247(v=vs.85).aspx#short_vs._long_names\n\n\u003e To specify an extended-length path, use the \"\\\\?\\\" prefix. For example, \"\\\\?\\D:\\very long path\".\n\nMy workaround looks like this basically:\n\n```\nvar os = require('os');\nif (os.platform() == 'win32') {\n var prefix = \"\\\\\\\\?\\\\\";\n var Module = require('module');\n Module._extensions['.node'] = function (module, modulePath) {\n if (modulePath.indexOf(prefix) !== 0) {\n modulePath = prefix + modulePath;\n }\n return process.dlopen(module, modulePath);\n }\n}\n```\n\nIt 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](https://github.com/nodejs/node/blob/master/lib/module.js#L469) to essentially have this same functionality. \n\nWhat do you think? Are there any gotcha's or can anyone think of a reason why this wouldn't work in the general case?\n","author":{"url":"https://github.com/justinmchase","@type":"Person","name":"justinmchase"},"datePublished":"2015-09-19T20:49:37.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":11},"url":"https://github.com/2964/node/issues/2964"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:6403124a-6feb-633e-bdb3-92239d03132e |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | D698:35FB06:15CC2C0:1E57247:6A4DF244 |
| html-safe-nonce | 5449fe43685dd25929c28a594c7808cd6a06da6c9fe49d6676f4b5dc42511958 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJENjk4OjM1RkIwNjoxNUNDMkMwOjFFNTcyNDc6NkE0REYyNDQiLCJ2aXNpdG9yX2lkIjoiMTU2MDczNzEyMDgyMTA0Nzg3NiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | b59ef597582f3991bd66863719454c6f3c1cf28d2084dd53f383fc6bc06217f7 |
| hovercard-subject-tag | issue:107355289 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/nodejs/node/2964/issue_layout |
| twitter:image | https://opengraph.githubassets.com/b4b4fb968b66f86d4e45b9db66264c264b6ff0af77f196bbbddb3999d5494232/nodejs/node/issues/2964 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/b4b4fb968b66f86d4e45b9db66264c264b6ff0af77f196bbbddb3999d5494232/nodejs/node/issues/2964 |
| og:image:alt | 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 filenam... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | justinmchase |
| hostname | github.com |
| expected-hostname | github.com |
| None | 5818716c93c6a2925b815402541a32814e43a7b1261c322b0c2df75224289566 |
| turbo-cache-control | no-preview |
| go-import | github.com/nodejs/node git https://github.com/nodejs/node.git |
| octolytics-dimension-user_id | 9950313 |
| octolytics-dimension-user_login | nodejs |
| octolytics-dimension-repository_id | 27193779 |
| octolytics-dimension-repository_nwo | nodejs/node |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 27193779 |
| octolytics-dimension-repository_network_root_nwo | nodejs/node |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | f4bb89367ca678f057d79b1abc45d6675b1bd5b2 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width