How to deploy Node.js application with deep node_modules structure on Windows?

前端 未结 8 1182
北荒
北荒 2020-11-30 17:11

I\'ve run into a curious issue - apparently some Node.js module have so deep folder hierarchies that Windows copy command (or PowerShell\'s C

相关标签:
8条回答
  • 2020-11-30 18:09

    I found one solution from Microsoft Node.js Guidelines.

    • Start in a short path (e.g. c:\src)
    • > npm install -g rimraf delete files that exceed max_path
    • > npm dedupe moves duplicate packages to top-level
    • > npm install -g flatten-packages moves all packages to top-level, but can cause versioning issues
    • Upgrade to npm@3 which attempts to the make the node_modules folder heirarchy maximally flat.
      • Ships with Node v5
      • Or… > npm install –g npm-windows-upgrade
    0 讨论(0)
  • 2020-11-30 18:11

    I don't think there's any great solution given your constraints, but here are some things that may help.

    • Try using npm dedupe to optimize your directory hierarchy which may shorten some paths
    • Use npm install --production to install without the development tools
    • Take some of those deeply nested dependencies (just enough to avoid the problem, I suggest) and move them to the top-level node_modules directory. Just keep track of them so you know which are your true dependencies and which are workarounds for this problem.
    • OR move some of those deep dependencies to the highest node_modules directory under your_project/node_modules/pkg_with_deep_deps that will allow them to have short enough paths but still work. So this would be your_project/node_modules/pkg_with_deep_deps/node_modules.
      • I think require should be able to find those properly at run time. You'll just need to clearly document what you have manually changed, why you have done it, and keep your own true dependencies accurately represented in package.json

    Here is a github issue discussion that elaborates on this problem in detail.

    0 讨论(0)
提交回复
热议问题