Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

node.js local modules :cannot find module error

I am trying to implement local modules in my application

1.Project root folder i have created folder named test with a file named index.js

      module.exports  = {

     myFunction:function(){
       console.log('ok');
     }
}

2.Added the following in package.json in the root folder

"dependencies": { 
    "test-module": "file:test"
  }

3.When i try to import var module = require('test-module'); in app.js i got this error

Cannot find module 'test-module'

like image 954
shellakkshellu Avatar asked Feb 26 '18 12:02

shellakkshellu


1 Answers

you can provide a path to a local directory that contains a package

{
  "name": "baz",
  "dependencies": {
    "bar": "file:../foo/bar"
  }
}

and perform npm install -s or npm install --save reference

like image 99
Akhilesh krishnan Avatar answered Oct 19 '22 23:10

Akhilesh krishnan