首页 > 解决方案 > 在 Ubuntu 18.04 上安装 node-sass 失败

问题描述

我有一个简单的 next.js 项目,我是按照他们的教程创建的。它在我的 Windows 开发机器上构建和运行良好。

我想在 Ubuntu 18.04.02 LTS 上部署它,但是当我克隆 git 项目并运行它时npm install,它无法安装 node-sass,并出现以下错误消息:

> node-sass@4.12.0 install /var/www/example.com/beta/node_modules/node-sass
> node scripts/install.js

internal/modules/cjs/loader.js:584
    throw err;
    ^

Error: Cannot find module '/var/www/example.com/beta/node_modules/node-sass/scripts/install.js'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:582:15)
    at Function.Module._load (internal/modules/cjs/loader.js:508:25)
    at Function.Module.runMain (internal/modules/cjs/loader.js:754:12)
    at startup (internal/bootstrap/node.js:283:19)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:622:3)
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.9 (node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.9: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! node-sass@4.12.0 install: `node scripts/install.js`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the node-sass@4.12.0 install 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: ...

这是日志文件的要点。请参阅错误的最后几行(我已经包含了整个文件,以防有其他有用的信息)。

我的 NodeJS 版本是 10.15.3,我的 NPM 版本是 6.4.1。我不确定如何在 Ubuntu 上运行 next.js 项目。

标签: node.jsnpmubuntu-18.04node-sass

解决方案


显然,我需要用--unsafe-perms标志安装它:

npm install --unsafe-perms

没有解释为什么它需要这个,而且unsafe很多人不推荐这个词。

此外,文件夹权限需要使脚本可以创建文件夹。我必须创建一个文件夹me,在那里克隆 repo,运行npm install --unsafe-perms,然后将权限设置为生产 Web 服务器。

参考请看这里


推荐阅读