简体   繁体   English

如何从本地文件夹安装 npm 模块?

[英]How to install npm module from local folder?

I downloaded a package from github: list.fuzzysearch.js .我从 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然后在我的项目文件夹中,我按如下方式安装它: 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.当我使用 webpack 捆绑我的项目 js 时,出现以下错误,这似乎错过了我安装的软件包所需的某些模块。

Question 1 : Should I do a npm install in the downloaded package's folder first, before I install this package into my project.问题 1 :在我将这个包安装到我的项目之前,我应该先在下载的包的文件夹中进行npm install吗? ie: ~/local/folder/list.fuzzysearch.js-master$ npm install即: ~/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?问题二:在app.js中导入模块时,路径怎么写? 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') ?import module from modulePath import module from , that modulePath`,我是否应该只将模块名称(例如“react”)或 js 文件的路径放在 node_module 文件夹中(例如“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?问题 3 :有没有办法找出模块的所有传递依赖项,并一路安装它们?

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:我的应用程序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.看起来您要使用的脚本是一个 npm 包,即使它没有发布到 npm 注册表。 This is how you can add it to your project:您可以通过以下方式将其添加到您的项目中:

  1. Add "list.fuzzysearch": "javve/list.fuzzysearch.js" under dependencies in your package.jsonpackage.json dependencies "list.fuzzysearch": "javve/list.fuzzysearch.js"下添加"list.fuzzysearch": "javve/list.fuzzysearch.js"
  2. npm install as usual像往常一样npm install
  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. npm 客户端在安装包的位置方面非常灵活。 Here's the relevant documentation .这是相关文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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