NVM is a life saver when you want to work with multiple version of node.js

NVM

Fixing – Error: Cannot find module ‘C:\Program Files\nodejs\node_modules\npm\bin\npm-cli.js’

A very common issue most people face when working with nvm tool is that after a fresh setup of this tool the npm command does not seem to find the npm-cli.js. The reason being that the setup process fail to copy few needed files to the expected location.

Though there is no official fix available for this issue as of now, a work around is available as below:

Existing environment:

  • Windows 10 professional x64
  • nvm installed path – C:\nvm

Steps

Visit the url – https://nodejs.org/en/download/releases/ and download the source for the node.js version that you are trying to work with.

Extract the zip content and copy the npm folder to “C:\nvm\v8.16.0\node_modules

once you are done with the above, you can use the npm command without any issue:

Note: You will need to repeat the above steps for each version of node.js that you are intending to use

if you don’t patch the installation as shown above, you will face with the following error:

Error: Cannot find module 'C:\Program Files\nodejs\node_modules\npm\bin\npm-cli.js'
    at Function.Module._resolveFilename (module.js:547:15)
    at Function.Module._load (module.js:474:25)
    at Function.Module.runMain (module.js:693:10)
    at startup (bootstrap_node.js:188:16)
    at bootstrap_node.js:609:3
module.js:549
    throw err;
    ^

Error: Cannot find module 'C:\Program Files\nodejs\node_modules\npm\bin\npm-cli.js'
    at Function.Module._resolveFilename (module.js:547:15)
    at Function.Module._load (module.js:474:25)
    at Function.Module.runMain (module.js:693:10)
    at startup (bootstrap_node.js:188:16)
    at bootstrap_node.js:609:3

Pre-Populating Folder(s) in Document Library with the Help of List Instance Definition

Scenario:

Today when I was working on a requirement, I had the need to create a customized picture library. To create this picture library the required List Schema, Definition, Instance Template, etc. were created.

Challenge:

One challenge I had at the end was, that this Library had to be pre-populated with a folder to store some control files.
Here is how it was resolved:

Note: I will not explain how the list definition and schema were created as there are several posts out there to help.

Solution:

In the List Instance definition (manifest file), you just have to add the line shown below (Module.. Path..):

   1:  <?xml version="1.0" encoding="utf-8" ?>
   2:  <Elements xmlns="http://schemas.microsoft.com/sharepoint/">
   3:   
   4:    <ListInstance FeatureId="327B763B-A5E7-4ac2-8458-B6570D362C0B"
   5:                 Id="WattsUpImagesLibrary"
   6:                 Title="$Resources:MyResource,ListInstance_WattsUpImages_DisplayName"
   7:                 Description="$Resources:MyResource,ListInstance_WattsUpImages_Description"
   8:                 Url="WattsUpImagesLibrary"
   9:                 TemplateType="3111" 
  10:                 OnQuickLaunch="FALSE" />
  11:    <!-- Adding a folder to the list instance-->
  12:    <Module Path="ControlFiles" Url="WattsUpImagesLibrary/ControlFiles" />
  13:  </Elements>

Please take a special note of the URL attribute, the value “WattsUpImagesLibrary” is the one used above as URL of the instance.

The output as a result of this:

image

IMPORTANT: To be able to create folder in Document Library, your list need to have the content reference of “0x0120” OR a custom one derived from it in the format of 0x0120 + 00 + <Guid>