Newman installed -g results in VSCode error: Cannot find module 'newman'

If npm and newman are installed from a WSL Debian Distro, I then do a “code .” from the wsl command line and open the Visual Studio interface, how can I make those packages visible by the node scripts running in visual studio? Currently via the terminal in Visual Studio and the WSL command line all users, package versions and library locations look the same. However, when I run a node script with “const newman = require(‘newman’);” I am getting the "Cannot find module.

As recommended, newman was installed with the -g option.


Hey @JillLancaster,

If you’re using Newman in a script, you would need to create a package.json file for that project, if you haven’t already, then install that module using this command:

npm install -S newman

This will install the node_modules and add an entry under the dependencies in the package.json file.


Thanks for the response. I am a Newbie to nodejs, npm, wsl and visual studio (about 4 months of sporadic use). For that reason I am trying to log in detail
the environment set up so that it can be consistently repeated by myself and others in the future. By doing that I am hoping to avoid the issues I have been running into with the reporters not being found. Thanks for bearing with me on all the questions.

I am confused as to what the steps should have been when using a combination of WSL, debian linux distro, Node, Visual Studio, and Newman. My confusion is
how to share the newman which I installed in the distro with visual studio and why the currently installed one does not get recognized. Several of the documentation links on npm mentioned installing any package you would use as a command with the –g option.
The –g option should make the package available for all directories for that user, correct? When I install node in WSL Visual Studio is aware of it.

I ran sudo npm install -g newman on the WSL command line (debian distro). And I can see that the install worked on the WSL command line. So my question is why would the npm install –S be required in Visual studio. Wouldn’t that create another local node_modules directory? And why is
that needed?



jillski@DESKTOP-21UQP5M:~ npm config editjillski@DESKTOP-21UQP5M:~ node -v


jillski@DESKTOP-21UQP5M:~$ npm -v


jillski@DESKTOP-21UQP5M:~$ newman -v


jillski@DESKTOP-21UQP5M:~$ which node


jillski@DESKTOP-21UQP5M:~$ which npm


jillski@DESKTOP-21UQP5M:/mnt/d/mddb_qa$ which newman


jillski@DESKTOP-21UQP5M:/mnt/d/mddb_qa$ ls -ltr /usr/bin/newman

lrwxrwxrwx 1 root root 40 Jan 7 13:53 /usr/bin/newman -> …/lib/node_modules/newman/bin/newman.js

jillski@DESKTOP-21UQP5M:/mnt/d/mddb_qa$ ls -ltr /usr/lib/node_modules/newman/

total 88

-rw-r–r-- 1 root root 36308 Oct 26 1985

-rw-r–r-- 1 root root 14348 Oct 26 1985

-rw-r–r-- 1 root root 11357 Oct 26 1985

-rw-r–r-- 1 root root 649 Oct 26 1985 index.js

-rw-r–r-- 1 root root 14317 Oct 26 1985 CHANGELOG.yaml

drwxr-xr-x 1 root root 512 Jan 7 13:53 test

drwxr-xr-x 1 root root 512 Jan 7 13:53 lib

drwxr-xr-x 1 root root 512 Jan 7 13:53 bin

drwxr-xr-x 1 root root 512 Jan 7 13:53 examples

drwxr-xr-x 1 root root 512 Jan 7 13:53 npm

drwxr-xr-x 1 root root 512 Jan 7 13:53 docker

-rw-r–r-- 1 root root 3292 Jan 7 13:53 package.json

drwxr-xr-x 1 root root 512 Jan 7 13:53 node_modules

Hey @jilllancaster

I’m not completely sure about the context of what you’re doing or have worked with a couple of those things you mentioned so I can only speak from the way that I know how to use Newman in the 2 different ways.

When using the -g flag you’re installing that globally so that will give you the ability to run that from the cli in any directory on your system (depending on your setup - I don’t know them all :slight_smile: )

For example:

newman run collection.json -e environment.json

So that command would work straight from the cli but using it with a node script would be different because you’re then using it as a library (like any other npm module that the script could be referencing) which has a different syntax for running the collections.

For this, you would need to install it in the project directory rather than globally. If you have a project already (where your newman node script is located) you can use the npm init command, that will create a package.json file.

Then, to install newman as a library, use the npm install -S newman command from that project directory. I added the -S flag so that it adds that to the dependencies object in the package.json file. When distributing that project to other people, all they would need to do is use the npm install command, rather than installing all the individual modules that the project might require.

Then you would be using newman in the node script like this:

const newman = require('newman');{
    collection: require('collection.json'),
    environment: require('environemnt.json')

As you can see, the way you would start the Collection run via a script would be different than from running in the cli using the globally installed package.

Hope that helps and doesn’t add to the confusion :slight_smile:


Just to avoid wasting your time I was able to figure this out. Installing it globally would only be required if using newman as a command? Installing it locally
is required to update the package.json so that the package.json can be used to install all the dependencies in the future (and stored in Git). I don’t believe it had anything to do with Visual Studio at all.

Thanks for the initial response.


1 Like

Perfect clarification. Thanks!


I was able to get all packages installed and the collections back up and running under Visual Studio. The next step was to redo (package and install) the custom
reporter. Other scripts which contain the same statements run the collections successfully currently execute under VS and using node. The output of the install shows success.

However, when I build a reporter I am getting the error below. I have tried the scenario in the attached zip file with both the –g option and without (local)
for the npm install of the reporter. There must be some piece that I am missing, because right now I have newman and the reporter installed both locally and globally and it cannot be found.

I am hoping there is something which you see being done incorrectly.



jillski@DESKTOP-21UQP5M:/mnt/d/mddb_qa$ node execCollectionAndReport.js

newman: could not find “samplereporter” reporter

ensure that the reporter is installed in the same directory as newman

please install reporter using npm

(Attachment is missing)

the .zip file with all the details was rejected. Hopefully these will provide enough information

The issue is resolved and I believe it was caused by changes made to the reporter files in VS which were not saved. If I determine any differently I will let you know, however, all is working at present and I’ve been able to document and repeat the steps to create a simple reporter.