0

I have done npm install ./pathtolocalfolder --save. My package.json has a dependency with name: file: ../pathtolocalfolder.

How do I import the folder in my project? npm can't resolve ./node_modules/folder or folder.

m02ph3u5
  • 3,022
  • 7
  • 38
  • 51
  • Why use npm if your file is local? See https://stackoverflow.com/questions/15806241/how-to-specify-local-modules-as-npm-package-dependencies – m02ph3u5 Jun 04 '20 at 10:19

1 Answers1

0

I just tested this and it works fine.

You don't even need to use npm install ./testmodule --save but your module must have package.json

Main ./package.json with reference to testmodule

{
  "name": "npmtest",
  "version": "1.0.0",
  "description": "",
  "main": "app.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "testmodule": "file:testmodule"
  }
}

Main ./app.js

var testmod = require('testmodule');

testmod.run();

./testmodule/package.json

{
  "name": "testmodule",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC"
}

./testmodule/index.js

exports.run = function() { console.log('testmodule'); }
Molda
  • 5,619
  • 2
  • 23
  • 39