首页 > 解决方案 > 永远安装 npm 和 mechanic 时出错

问题描述

我的目标是在我的 Windows 10 机器上为 ApostropheCMS ( https://apostrophecms.org/docs/ )设置开发环境。为了实现这个目标,我在 Docker 容器中运行 CentOS,我按照以下说明安装 Apostrophe: https ://apostrophecms.org/docs/tutorials/intermediate/deployment.html

我或多或少能够无错误和无警告地完成以下安装:

## My docker command, to get CentOS bash in a new container
docker run -it centos bash

## Apostrophe CMS install script, run inside CentOS Bash
# Grab some command line basics
yum install wget rsync perl git nano
# Allow the use of the EPEL ("Extra Packages for Enterprise Linux") repository
yum install epel-release
# Front end proxy webserver
yum install nginx
# Install node, imagemagick, npm, and compiler tools so an efficient
# mongo driver can be compiled by npm
yum install gcc automake autoconf libtool make nodejs ImageMagick npm
# Install mongodb
yum install mongodb-server mongodb
# Allow non-root users to run command line applications installed with
# "npm install -g", otherwise it is not very useful
chmod -R a+r /usr/lib/node_modules/

但是,我从 npm 永久安装和 mechanic 的两个命令收到错误或警告。错误在下面的附录中。

# Used to run things indefinitely restarting as needed
npm install -g forever
# Used to manage nginx
npm install -g mechanic

我的问题是:

  1. 我什至需要永远和机械师来开发开发实例吗?即,我要做的就是在本地开发并部署到服务器?
  2. 如果是,我怎样才能让这些安装没有错误?

我意识到这些都是菜鸟级别的问题。我是 CentOS、Docker 和撇号的新手。感谢您的耐心、理解和建议。


附录:错误

倒数第二个命令:

# Used to run things indefinitely restarting as needed
npm install -g forever

给我:

npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@^1.0.0 (node_modules/forever/node_modules/chokidar/node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.4: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})

最后的命令:

# Used to manage nginx
npm install -g mechanic

给我:

gyp WARN EACCES user "undefined" does not have permission to access the dev dir "/root/.node-gyp/6.14.2"
gyp WARN EACCES attempting to reinstall using temporary dev dir "/usr/lib/node_modules/mechanic/node_modules/fs-ext/.node-gyp"
make: Entering directory `/usr/lib/node_modules/mechanic/node_modules/fs-ext/build'
  CXX(target) Release/obj.target/fs-ext/fs-ext.o
make: g++: Command not found
make: *** [Release/obj.target/fs-ext/fs-ext.o] Error 127
make: Leaving directory `/usr/lib/node_modules/mechanic/node_modules/fs-ext/build'
gyp ERR! build error
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack     at ChildProcess.onExit (/usr/lib/node_modules/npm/node_modules.bundled/node-gyp/lib/build.js:276:23)
gyp ERR! stack     at emitTwo (events.js:106:13)
gyp ERR! stack     at ChildProcess.emit (events.js:191:7)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:219:12)
gyp ERR! System Linux 4.9.87-linuxkit-aufs
gyp ERR! command "/usr/bin/node" "/usr/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "configure" "build"
gyp ERR! cwd /usr/lib/node_modules/mechanic/node_modules/fs-ext
gyp ERR! node -v v6.14.2
gyp ERR! node-gyp -v v3.4.0
gyp ERR! not ok
/usr/lib
`-- (empty)

npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@^1.0.0 (node_modules/mechanic/node_modules/chokidar/node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.4: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
npm ERR! Linux 4.9.87-linuxkit-aufs
npm ERR! argv "/usr/bin/node" "/usr/bin/npm" "install" "-g" "mechanic"
npm ERR! node v6.14.2
npm ERR! npm  v3.10.10
npm ERR! code ELIFECYCLE

npm ERR! fs-ext@0.5.0 install: `node-gyp configure build`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the fs-ext@0.5.0 install script 'node-gyp configure build'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the fs-ext package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     node-gyp configure build
npm ERR! You can get information on how to open an issue for this project with:
npm ERR!     npm bugs fs-ext
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!     npm owner ls fs-ext
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR!     /npm-debug.log
npm ERR! code 1

标签: npmcentosapostrophe-cms

解决方案


事实上,在我们的文档站点上的这个配方中有一些疏忽。yum您缺少的关键包是gcc-c++.

yum install gcc-c++

此外,我还更新了整个配方,以包含来自更好存储库的更好版本的 node 和 mongodb。(EPEL 存储库确实提供了 MongoDB 的一个版本,但它已经过时了。该存储库中的节点版本稍微好一点,但为什么没有 8.x,因为它是当前的长期支持版本。)

感谢您提请我们注意。


推荐阅读