I've seen too many different types of answers about this. And I had to try to out all the different methods to finally understand what was going on. I didn't have a plugins:
section in my karma.conf.js
either.
So I have a project AwesomeKarmaTests
which contains all the files inside inside a folder of the same name.
AwesomeKarmaTests
\package.json
\karma.conf.js
\node_modules
\karma
\karma-jasmine
...
The node_modules
directory is obviously going to be created when you cd AwesomeKarmaTests
and run npm install
.
npm
would then go through the contents of the package.json
in the folder from which it was invoked and install all the packages listed and further dependencies if required.
Contents of my package.json
{
"name": "AwesomeKarmaTests",
"version": "1.0.0",
"devDependencies": {
"karma": "^1.6.0",
"karma-jasmine": "^1.1.0",
"karma-junit-reporter": "^1.2.0",
"karma-ng-html2js-preprocessor": "^1.0.0",
"karma-phantomjs-launcher": "^1.0.4"
}
}
I encountered this problem (Can not load "ng-html2js"
) initially because karma
was installed globally in my system. The global karma
installation would try to look for karma-ng-html2js-preprocessor
package globally, and it would obviously fail to find it as I hadn't installed the pre-processor globally.
And I couldn't understand what was going on as every single one of the devDependencies
in the package.json
was already installed in the node_modules
directory inside the root folder of the project.
I kept running karma start
from AwesomeKarmaTests
folder without realizing that it was the global installation of karma that was being executed (silly me).
However after uninstalling karma
from my global installation I started getting /c/Users/fastasticUser/AppData/Roaming/npm/karma: No such file or directory
errors. That was when I realized my mistake.
Then I changed my approach. I started running my tests using the following command, explicitly specifying the path of the local installation of karma.
./node_modules/karma/bin/karma start karma.conf.js
from AwesomeKarmaTests
directory. And as mentioned in several other posts, karma did pick its sibling packages and plugins.
So remember to use the local versions of the karma
package when relying on other locally installed plugins or packages, else karma
will have trouble identifying what you want it to do.