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

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

提交回复
热议问题