使用 optimist.js 文件中的 npm 安装优化

install optimise with npm from optimist.js file

正在尝试修复 Carto tool from Mapbox 在 Ubuntu 14.04 上的离线安装。目前,节点给我一个错误,它找不到 optimist 模块。我可以手动找到一个 optimist.js 文件,但它不像其他 Carto 依赖项那样位于 "proper" node_modules 目录下(例如 underscore)。我是 非常 的 npm 和节点新手,所以我的问题是 "is there a way to properly install optimise from this optimist.js file I have?"

如果您只想使用这个包,

$ npm install -g carto

应该足以让您入门。请注意,您可能需要为该命令使用 sudo

Node.js 以名为 "npm". Every npm project has a package.json at its root directory that specifies its dependencies, package name, version, et al. By looking at carto's package.json 的包管理器为中心,即使您成功安装了 optimist,您也会遇到更多 require 错误。

如果你想开发这个包,在使用 Git 运行

克隆它之后
$ npm install

目录里面。这将为您安装所有依赖项(包括 devDependencies 在您安装软件包本身时未安装的依赖项)。

关于 Node.js 如何工作的教程很多,例如 http://nodeguide.com/beginner.html。这些应该会给你比这个答案更全面的看法。

使用像 npm 这样的合适的包管理器,你永远不应该使用在互联网上找到的随机脚本来伪造它作为一个模块。

祝你好运!


更新 既然知道 npm 是如何工作的,如果你想在本地安装它,你可以这样做

# With Internet
# Make a cache
$ mkdir carto-cache
# Make a temporary directory where the initial copy of carto is installed
$ mkdir to-be-discarded
$ cd to-be-discarded
# Now install the package, and cache the package in carto-cache
$ npm install --cache ../carto-cache --prefix . carto
# You can now remove to-be-discarded, and copy carto-cache to wherever you want.

# Without internet
$ npm install --cache carto-cache --cache-min 999999999 -g carto

(源自https://github.com/npm/npm/issues/2568