modeller
modeller

Reputation: 3850

How to install npm module from local folder?

I downloaded a package from github: list.fuzzysearch.js. Unzipped it to a folder

Then in my project folder, I install it as follows: npm install Path/to/LocalFolder/list.fuzzysearch.js-master -S

When I bundle my project js using webpack, I got below error, which seems to miss some module required by the package I installed.

Question 1: Should I do a npm install in the downloaded package's folder first, before I install this package into my project. i.e: ~/local/folder/list.fuzzysearch.js-master$ npm install

Question 2: when I import a module in my app.js, how do I write the path? i.e. import module frommodulePath, thatmodulePath`, shall I just put module name (e.g. 'react'), or the path to the js file in node_module folder (e.g. 'node_module/react/dist/react.js') ?

Question 3: is there a way to find out all transitive dependency of a module, and install them along the way?

errors:

ERROR in ./~/list.fuzzysearch.js/index.js
Module not found: Error: Cannot resolve module 'classes' in /home/mypc/IdeaProject/OpenDimSum/frontend/node_modules/list.fuzzysearch.js
 @ ./~/list.fuzzysearch.js/index.js 1:14-32

ERROR in ./~/list.fuzzysearch.js/index.js
Module not found: Error: Cannot resolve module 'extend' in /home/mypc/IdeaProject/OpenDimSum/frontend/node_modules/list.fuzzysearch.js
 @ ./~/list.fuzzysearch.js/index.js 3:13-30

ERROR in ./~/list.fuzzysearch.js/index.js
Module not found: Error: Cannot resolve module 'to-string' in /home/mypc/IdeaProject/OpenDimSum/frontend/node_modules/list.fuzzysearch.js
 @ ./~/list.fuzzysearch.js/index.js 4:15-35

ERROR in ./~/list.fuzzysearch.js/index.js
Module not found: Error: Cannot resolve module 'get-by-class' in /home/mypc/IdeaProject/OpenDimSum/frontend/node_modules/list.fuzzysearch.js
 @ ./~/list.fuzzysearch.js/index.js 5:17-40

my app javascript:

require('../../../node_modules/bootstrap/dist/css/bootstrap.css')
require ('../public/styles.css')
require ('../index.html')
import React from 'react'
import {render} from 'react-dom'
import 'list.js'
import 'list.fuzzysearch.js'
require('../../../node_modules/bootstrap/dist/js/bootstrap')

Upvotes: 1

Views: 8322

Answers (1)

Nick Ribal
Nick Ribal

Reputation: 2109

Looks like the script you want to use is an npm package, even though it isn't published to the npm registry. This is how you can add it to your project:

  1. Add "list.fuzzysearch": "javve/list.fuzzysearch.js" under dependencies in your package.json
  2. npm install as usual
  3. import fuzzysearch from 'list.fuzzysearch'

The npm client is really flexible when it comes to where a package can be installed from. Here's the relevant documentation.

Upvotes: 2

Related Questions