简体   繁体   English

在 Ubuntu 18.04 上安装 node-sass 失败

[英]Installing node-sass fails on Ubuntu 18.04

I have a simple next.js project, which I created following their tutorial.我有一个简单的 next.js 项目,我是按照他们的教程创建的。 It builds and runs well on my Windows development machine.它在我的 Windows 开发机器上构建并运行良好。

I want to deploy it on Ubuntu 18.04.02 LTS but when I clone the git project and run npm install it fails to install node-sass with the following error message:我想在 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: ...

Here is a gist of the log file .这是日志文件的要点。 See the last few lines for the error (I have included the whole file in case there is other information that is useful).查看错误的最后几行(我已经包括了整个文件以防有其他有用的信息)。

My NodeJS version is 10.15.3 and my NPM version is 6.4.1.我的 NodeJS 版本是 10.15.3,我的 NPM 版本是 6.4.1。 I am not sure how to run next.js project on Ubuntu.我不确定如何在 Ubuntu 上运行 next.js 项目。

尝试在安装所有其他软件包之前手动安装它 - 可能存在一些软件包依赖性问题。

npm install node-sass@4.12.0 && npm install

Apparently, I needed to install it with --unsafe-perms flag: 显然,我需要使用--unsafe-perms标志安装它:

npm install --unsafe-perms

No explanation onto why it needs this and the unsafe word is not recommended by many. 没有解释为什么它需要这个和unsafe词不被许多人推荐。

In addition, the folder permissions needed to be in such a way that the script can create folders. 此外,文件夹权限需要以脚本可以创建文件夹的方式进行。 I had to create a folder as me , clone the repo there, run the npm install --unsafe-perms , and then set the permissions as of a production web server. 我必须像me一样创建一个文件夹,在那里克隆repo,运行npm install --unsafe-perms ,然后设置生产Web服务器的权限。

For reference see here . 供参考,请参见此处

This module has striction about node versions, as below:该模块对节点版本有严格限制,如下所示:

在此处输入图像描述

solution is: specify the module version when you install it.解决方案是:安装时指定模块版本。

PS Other approach: PS其他方法:

if you just want to use scss/sass, use this module:如果您只想使用 scss/sass,请使用此模块:

 npm install sass sass-loader

this does NOT work for: node 16, ubuntu 18这不适用于:节点 16、ubuntu 18

npm install --unsafe-perms

for node 14, ubuntu 18, I can install it:对于节点 14、ubuntu 18,我可以安装它:

npm install node-sass

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

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