【问题标题】:npm building issues for SyntaxHighlighterSyntaxHighlighter 的 npm 构建问题
【发布时间】:2020-04-05 02:54:31
【问题描述】:

我是 npm 的初学者,正在尝试通过首先使用 git 克隆它来构建 SyntaxHighlighter 版本 4,但失败了。以下是我得到的错误:

1 error generated.
make: *** [Release/obj.target/binding/src/create_string.o] Error 1
gyp ERR! build error
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack     at ChildProcess.onExit (/Users/name/syntaxhighlighter/node_modules/node-gyp/lib/build.js:262:23)
gyp ERR! stack     at ChildProcess.emit (events.js:311:20)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:275:12)
gyp ERR! System Darwin 19.3.0
gyp ERR! command "/usr/local/bin/node" "/Users/name/syntaxhighlighter/node_modules/node-gyp/bin/node-gyp.js" "rebuild" "--verbose" "--libsass_ext=" "--libsass_cflags=" "--libsass_ldflags=" "--libsass_library="
gyp ERR! cwd /Users/name/syntaxhighlighter/node_modules/node-sass
gyp ERR! node -v v12.16.1
gyp ERR! node-gyp -v v3.8.0
gyp ERR! not ok 
Build failed with error code: 1
npm WARN notsup Unsupported engine for karma@0.13.22: wanted: {"node":"0.10 || 0.12 || 4 || 5"} (current: {"node":"12.16.1","npm":"6.13.4"})
npm WARN notsup Not compatible with your version of node/npm: karma@0.13.22
npm WARN syntaxhighlighter@4.0.1 No description

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! node-sass@3.13.1 postinstall: `node scripts/build.js`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the node-sass@3.13.1 postinstall script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/name/.npm/_logs/2020-04-05T02_52_17_048Z-debug.log

【问题讨论】:

  • 添加要克隆的命令。
  • 我先使用 git 克隆它,然后运行 ​​cd syntaxhighlighternpm install
  • 您使用的是哪个操作系统。
  • macOS Catalina.

标签: node.js npm build syntaxhighlighter


【解决方案1】:

robdonn 的 NVM 解决方案有效,但是,当我运行多个版本的 Node(通过 NVM 管理)时,我遇到了一个非常不寻常的实例,它破坏了我的 ApiConnect/Loopback 客户端(仅在 Mac 上)。我从来不知道为什么,但意识到运行单个版本的 Node 解决了这个问题。

还想使用 syntaxhighlighter,我确实设法使用 Docker 容器生成了 syntaxhighlighter.js 文件。在克隆的目录中,我添加了 Dockerfile。

FROM node:5
# Create app directory
WORKDIR /usr/src/app

# Install app dependencies
# A wildcard is used to ensure both package.json AND package-lock.json are copied
# where available (npm@5+)
COPY package*.json ./

RUN npm install

# Bundle app source
COPY . .

此后我能够:

  1. 构建本地 docker 容器
docker build -t syntaxhighlighter .
  1. 运行容器,将我的本地dist 目录映射到容器的dist 目录
docker run -i --volume ~/github/syntaxhighlighter/dist:/usr/src/app/dist syntaxhighlighter
  1. 获取本地运行容器的容器 ID
docker ps
  1. 使用容器 ID 进入容器(也可以将 CMD ['/bin/sh'] 放入我的 Dockerfile 中)
docker exec -it <the-container-id> /bin/sh
  1. 从 Node v5 容器运行 gulp 构建。由于我将本地 dist 目录映射到容器的 dist 目录,因此我在本地获取输出。
./node_modules/gulp/bin/gulp.js build --brushes=all  --compat

【讨论】:

    【解决方案2】:

    您遇到的问题是 SyntaxHighlighter 版本 4 太旧,并且您运行的 Node 版本不支持它的依赖项。

    错误来自的包是 Karma。尝试安装的 Karma 版本是 v0.13.22。该版本的 Karma 仅支持最高 Node 版本 5,而您似乎正在运行版本 12。

    您可以通过降级 Node 版本或使用 Node Version Manager (NVM) 等工具暂时降级 Node 版本来解决此问题。

    NVM

    【讨论】:

      【解决方案3】:

      尝试仅安装 node_modules。 cd /syntaxhighlighter/node_modules$ 然后尝试使用npm install 安装。 gulp.js 文件中有一些错误会导致安装过程出现问题。我已经尝试过旧版本,但没有一个可用。希望这会成功。

      【讨论】:

      • 我试了很多次都没有成功。通过查看提供的错误,还有什么我应该安装的吗?
      • 我已经使用了最新的 npm 6.13.4 版本。您能通过查看提供的错误代码确定我需要做什么吗?
      • 库中存在一些问题,即使在安装后它在基于 Linux 的系统上也无法正常工作。我已经在 windows 上试过了,效果很好。
      • 尝试再次克隆库,但这次使用 fork。您的先决条件已经满足。只是为了确认尝试使用叉子。也许之前没有克隆整个库。
      猜你喜欢
      • 2021-06-24
      • 2018-12-20
      • 1970-01-01
      • 2020-08-26
      • 2018-02-05
      • 2021-04-04
      • 2020-07-17
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多