43

I was getting the following error when I ran "karma start"

module.js:340 throw err; ^ Error: Cannot find module 'jasmine-core' at Function.Module._resolveFilename (module.js:338:15) at Function.require.resolve (module.js:384:19) at initJasmine (/usr/lib/node_modules/karma-jasmine/lib/index.js:8:42) at Array.invoke [as 0] (/usr/lib/node_modules/karma/node_modules/di/lib/injector.js:75:15) at get (/usr/lib/node_modules/karma/node_modules/di/lib/injector.js:48:43) at /usr/lib/node_modules/karma/lib/server.js:137:20 at Array.forEach (native) at Server._start (/usr/lib/node_modules/karma/lib/server.js:136:21) at invoke (/usr/lib/node_modules/karma/node_modules/di/lib/injector.js:75:15) at Server.start (/usr/lib/node_modules/karma/lib/server.js:101:18) at Object.exports.run (/usr/lib/node_modules/karma/lib/cli.js:231:26) at Object. (/usr/lib/node_modules/karma/bin/karma:3:23) at Module._compile (module.js:456:26) at Object.Module._extensions..js (module.js:474:10) at Module.load (module.js:356:32) at Function.Module._load (module.js:312:12)

Does anyone know why this is happening? I was running karma in a VM. I tried several npm install commands and nothing worked. After I shutdown my machine for the night and came back the next day the problem went away and everything is working again. So, I'm not blocked anymore.. Anyone have some thoughts on what could be happening?

Daniel Cohen
  • 538
  • 1
  • 4
  • 6
  • Something probably changed your system path and the restart loaded it fresh. – MBielski Sep 29 '15 at 14:32
  • 2
    Where you able to get your problem solved? http://stackoverflow.com/questions/35993875/error-cannot-find-module-jasmine-core – Leon Gaban Mar 14 '16 at 17:12
  • Possibly related: [https://stackoverflow.com/questions/33870520/](https://stackoverflow.com/questions/33870520/)? – Henke Jul 06 '20 at 13:49

6 Answers6

68

I solved using npm install jasmine-core --save-dev

lau.lun
  • 789
  • 5
  • 3
49

try install jasmine-core globally (Jasmine on NPM). use npm install -g jasmine-core

John
  • 4,786
  • 8
  • 35
  • 44
craigstar
  • 591
  • 3
  • 5
  • I tried both these answers, but still getting this error, mind a look? http://stackoverflow.com/questions/35993875/error-cannot-find-module-jasmine-core – Leon Gaban Mar 14 '16 at 17:12
  • 2
    `npm install jasmine-core --save-dev` this is better than global – Yumiko Sep 25 '16 at 00:27
8

Even with karma and karma-jasmine installed in the local project's node_modules you must still npm install jasmine.

So for a fresh Karma project:

  1. npm install karma karma-jasmine jasmine to install the required modules locally.

Optionally add --save-dev to write to your package.json. Note these do not need to be -g globally installed here.

  1. karma start

This step requires you to have Karma installed globally (sudo npm install -g karma).

Bradley Flood
  • 10,233
  • 3
  • 46
  • 43
8

Navigate to folder:

cd node_modules\karma-jasmine

Run:

npm install

This should download the required dependencies and fix the issue.

sswierczek
  • 810
  • 1
  • 12
  • 19
Snehal P
  • 171
  • 4
  • 8
0

Also, it is important to know the installation path where do you have karma.conf.js file.

spacedev
  • 1,086
  • 13
  • 13
0

I have this problem, and have tried every suggestion on the page without it fixing the problem. Well, I haven't yet rebooted, so I'll try that next, but I have closed my shell (git-bash) and re-opened it in case it was an environment variable problem. Something is wrong here and I don't think the problem has been identified yet.

John Deighan
  • 4,329
  • 4
  • 18
  • 19