简体   繁体   中英

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. ie: ~/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? ie import module from modulePath , that modulePath`, shall I just put module name (eg 'react'), or the path to the js file in node_module folder (eg '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')

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'
  4. ???
  5. PROFIT!!!

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM