I installed node dependencies with -g. But can't find module

nodejs

#1

Hi, I keep getting the error
Error: Cannot find module ‘nightmare’

I have installed the dependency globally. but the test.js fails when the test needs it.

test.js

var Nightmare = require('nightmare');

circle.yml

machine:
  node:
    version: 5.1.0

dependencies:
  pre:
    - npm install -g nightmare

test:
  pre: 
    - node acceptancetest/test.js
...

console:

$node acceptancetest/test.js
module.js:340
    throw err;
    ^

Error: Cannot find module 'nightmare'
    at Function.Module._resolveFilename (module.js:338:15)
    at Function.Module._load (module.js:289:25)
    at Module.require (module.js:366:17)
    at require (module.js:385:17)
    at Object.<anonymous> (/home/ubuntu/projectexchange/acceptancetest/test.js:1:79)
    at Module._compile (module.js:425:26)
    at Object.Module._extensions..js (module.js:432:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:313:12)

at Function.Module.runMain (module.js:457:10) node acceptancetest/test.js returned exit code 1

regards Rune


#2

I also tried this:

machine:
  node:
    version: 5.1.0

dependencies:
  pre:
    - npm install ${HOME}/${CIRCLE_PROJECT_REPONAME}/acceptancetest

test:
  pre: 
    - node acceptancetest/test.js
...

Where it finds and installs the package. But still test.js cant find the module.


#3

and added the path to the node_moduless

machine:
  environment:
    PATH: ${PATH}:${HOME}/${CIRCLE_PROJECT_REPONAME}/acceptancetest/node_modules/
...

still the same error…


#4

Hi,

Can you try your first example but not install the module globally (without -g)?


#5

Thanks Feliciano, that did the trick.


#6

Great! I hope you’re working on something awesome :slight_smile:


#7