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

前端 未结 8 1181
北荒
北荒 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:01

    I wrote a node module called "npm-flatten" that flattens your dependencies for you here: https://www.npmjs.org/package/npm-flatten

    If you are looking for a distrubtion, I also wrote a NuGet package that will integrate a complete node.js environment with your .NET project here: http://www.nuget.org/packages/NodeEnv/

    Feedback would be welcome.

    0 讨论(0)
  • 2020-11-30 18:02

    npm v3(released recently) solves this issue by flattening out the dependencies.. Check the release notes here in https://github.com/npm/npm/releases/tag/v3.0.0 under flat flat section.

    And the last comment on this issue https://github.com/npm/npm/issues/3697

    0 讨论(0)
  • 2020-11-30 18:03

    just to add to this... another thing that helped me was listing out all installed modules with npm ls.

    which will give you a tree of modules and versions... from there it's pretty easy to identify which ones are duplicates... npm dedupe didn't do anything for me. I'm not sure if that's a bug or what (Node v 10.16)

    So once you identify a duplicate module install it to the root node_module directory by using npm install dupemodule@1.2.3 --save-dev. The version is important.

    after that, I wiped out my node_modules directory and did a fresh npm install.

    Short version

    1. npm ls to get a list of all installed modules.
    2. look through those modules and identify duplicate modules (version is important)
    3. npm install module@version --save-dev to install those modules in the root node_modules directory and update package.json.
    4. rmdir node_modules to delete the node_modules directory.
    5. npm install to pull down a fresh copy of your dependencies.

    Once I did that, everything was much cleaner.

    I also recommend commenting your package.json file to show which ones were brought down to flatten the node_modules tree.

    0 讨论(0)
  • 2020-11-30 18:03

    Something that helped me was to map a local drive to my Node.js folder:

    net use n: \computername\c$\users\myname\documents\node.js /persistent:yes

    Before: c:\users\myname\documents\node.js\projectname (45 characters) After: n:\projectname (14 characters which is 31 chars less)

    In many cases this allowed some modules to be installed.

    I will say that I just re-discovered this problem today when I was attempting to backup all my code to a USB drive.

    "C:\Users\myname\Documents\Node.js\angular-phonecat\node_modules\karma\node_modules\chokidar\node_modules\anymatch\node_modules\micromatch\node_modules\regex-cache\node_modules\benchmarked\node_modules\file-reader\node_modules\extend-shallow\benchmark\fixtures is too long."

    Even when I tried to back them up using the N: drive letter it still failed in some cases due to path lengths but it was just enough to fix the one above.

    0 讨论(0)
  • 2020-11-30 18:04

    1) During release build, You can prevent Visual studio scanning these files / folder by setting the folder properties as a Hidden folder (JUST set it to node_modules). Reference: http://issues.umbraco.org/issue/U4-6219#comment=67-19103

    2) You can exclude files or folder that are published during packaging by including following XML node in the CsProject file.

    <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
      ...
      <OutputPath>bin\</OutputPath>
       <NoWarn>42016,41999,42017,42018,42019,42032,42036,42020,42021,42022</NoWarn>
      <ExcludeFilesFromDeployment>File1.aspx;File2.aspx</ExcludeFilesFromDeployment>
      <ExcludeFoldersFromDeployment>Folder1;Folder2</ExcludeFoldersFromDeployment>
    </PropertyGroup>
    
    0 讨论(0)
  • 2020-11-30 18:05

    This is a not a proper solution, rather a work around when you are in a hurry, but you can use 7-Zip to zip your folder, move the zipped file and unzip it without any issue.

    We used that solution to deploy a Node.js application where it was not possible to do a clean npm install.

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