"Error: The `libsass` binding was not found..." 在 nodejs 4.2.4 lts 中使用 docker 而不是 5.4.1



我正在使用nodejs 4.2.4和expressjs使用sass设置一个docker容器。

我的 Dockerfile:

FROM node:4.2.4-wheezy
COPY myapp /srv/www/
RUN rm -r /srv/www/node_modules || echo "Not removing /srv/www/node_modules,     directory did not exist"
#RUN npm update
#RUN npm install -g --silent node-sass
RUN cd /srv/www && npm install --silent
#RUN cd /srv/www && npm rebuild node-sass
EXPOSE 3000

快递.js项目是使用他们的生成器生成的

 express -css sass --hbs myapp

它生成一个带有此包的框架项目.json:

{
 "name": "myapp",
 "version": "0.0.0",
 "private": true,
 "scripts": {
   "start": "node ./bin/www"
  },
   "dependencies": {
   "body-parser": "~1.13.2",
   "cookie-parser": "~1.3.5",
   "debug": "~2.2.0",
   "express": "~4.13.1",
   "hbs": "~3.1.0",
   "morgan": "~1.6.1",
   "node-sass-middleware": "0.8.0",
   "serve-favicon": "~2.3.0"
  }
}

使用节点 4.2.4 在我的 Mac 上运行它工作正常,但在 docker 容器中运行它会给出以下错误:

philipp@Philipps-MacBook-Pro:~/node/expressv1 $docker run -it -P -w="/srv/www/" test_server_7 npm start 
npm info it worked if it ends with ok
npm info using npm@2.14.12
npm info using node@v4.2.4
npm info prestart myapp@0.0.0
npm info start myapp@0.0.0
> myapp@0.0.0 start /srv/www
> node ./bin/www
/srv/www/node_modules/node-sass-middleware/node_modules/node-sass/lib/extensions.js:158
    throw new Error([
    ^
Error: The `libsass` binding was not found in /srv/www/node_modules/node-sass-middleware/node_modules/node-sass/vendor/linux-x64-46/binding.node
This usually happens because your node version has changed.
Run `npm rebuild node-sass` to build the binding for your current node version.
    at Object.sass.getBinaryPath (/srv/www/node_modules/node-sass-middleware/node_modules/node-sass/lib/extensions.js:158:11)
    at Object.<anonymous> (/srv/www/node_modules/node-sass-middleware/node_modules/node-sass/lib/index.js:16:36)
    at Module._compile (module.js:435:26)
    at Object.Module._extensions..js (module.js:442:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:313:12)
    at Module.require (module.js:366:17)
    at require (module.js:385:17)
    at Object.<anonymous> (/srv/www/node_modules/node-sass-middleware/middleware.js:3:12)
    at Module._compile (module.js:435:26)

但是,如果我从 5.4.1-wheezy 扩展 docker 映像,它可以正常工作。libsass 和 node 似乎存在很多问题(这里、这里和这里)。我尝试了这些链接中的所有建议,其中一些仍保留在上面的 Dockerfile 中,但没有一个有任何效果。在某种程度上,如果我来自干净的节点安装,我将不得不重建节点sass对我来说也是没有意义的。有什么建议吗?

对于遇到相同问题的任何人来说,正如 pesho 在这里建议的那样,问题是由 nodejs 4.2.4 安装的 npm 2.x 在模式下不会运行脚本,导致这两个脚本失败:

npm WARN cannot run in wd node-sass@3.4.2 node scripts/install.js (wd=/srv/www/myapp/node_modules/node-sass-middleware/node_modules/node-sass)
npm WARN cannot run in wd node-sass@3.4.2 node scripts/build.js (wd=/srv/www/myapp/node_modules/node-sass-middleware/node_modules/node-sass)
可以使用 --

unsafe-perm 标志运行 npm 安装,但正如该标志所暗示的那样,它是不安全的。更好的方法是遵循Starefossens最佳实践并创建另一个用户。

最新更新