简体   繁体   中英

Installing node-sass fails on Ubuntu 18.04

I have a simple next.js project, which I created following their tutorial. It builds and runs well on my Windows development machine.

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:

> 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. I am not sure how to run next.js project on Ubuntu.

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

npm install node-sass@4.12.0 && npm install

Apparently, I needed to install it with --unsafe-perms flag:

npm install --unsafe-perms

No explanation onto why it needs this and the unsafe word is not recommended by many.

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.

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:

if you just want to use scss/sass, use this module:

 npm install sass sass-loader

this does NOT work for: node 16, ubuntu 18

npm install --unsafe-perms

for node 14, ubuntu 18, I can install it:

npm install node-sass

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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