NPM doesn't install module dependencies

前端 未结 16 1724
深忆病人
深忆病人 2020-12-02 06:39

This is my package.json for the module that I\'m including in the parent project:

{
  \"version\": \"0.0.1\",
  \"name\": \"module-name\",
  \"d         


        
相关标签:
16条回答
  • 2020-12-02 06:51

    if you inherited this code, it could be that the dependencies and versions were locked and you have a ./npm-shrinkwrap.json file.

    if your dependency is not listed in that file, it will never get installed with the npm install command.

    you will need to manually install the packages and then run npm shrinkwrap to update the shrinkwrap file.

    0 讨论(0)
  • 2020-12-02 06:51

    I suspect you're facing the issue where your package.json file is not in the same directory as your Gruntfile.js. When you run your grunt xxx commands, you get error an message like:

    Local Npm module "xxx" not found. Is it installed?
    

    For now, the solution is:

    • Create package.json in the same directory as Gruntfile.js
    • Define the modules required by your grunt project
    • Execute npm install to load them locally
    • Now the required grunt command should work.

    IMHO, it is sad that we cannot have grunt resolve modules loaded from a parent npm module (i.e. package.json in a parent directory within the same project). The discussion here seems to indicate that it was done to avoid loading "global" modules but I think what we want is loading from "my project" modules instead.

    0 讨论(0)
  • 2020-12-02 06:52

    OP may be true for an older version of node. However, I faced the same with node 4.4.1 as well.

    It very well may be linked to the node version you are using. Try to upgrade to a latest version. Certain dependencies don't load transitively if they are incompatible with node version.

    I found this by running npm update.

    After upgrading to latest version (4.4 -> 5.9); this got fixed.

    0 讨论(0)
  • 2020-12-02 06:55

    I had very similar issue, removing entire node_modules folder and re-installing worked for me. Learned this trick from the IT Crowd show!

    rm -rf node_modules
    npm install
    
    0 讨论(0)
  • 2020-12-02 06:57

    Another way to work this around is to add this into your module package.json scripts section

    "preinstall": "npm install {Packages You depend on}"
    

    what this will does is, it will install all packages needed by the module and you won't get that error.

    0 讨论(0)
  • 2020-12-02 07:02

    In my case it helped to remove node_modules and package-lock.json.

    After that just reinstall everything with npm install.

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