gpt4 book ai didi

node.js - "Error: The ` libsass ` binding was not found..."在 Nodejs 4.2.4 lts 中,但在 5.4.1 中使用 docker

转载 作者:太空宇宙 更新时间:2023-11-04 00:45:41 24 4
gpt4 key购买 nike

我正在使用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

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

 express -css sass --hbs myapp

使用此 package.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"
}
}

在我的 Mac 上使用 Node 4.2.4 运行它可以正常工作,但是在 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 似乎存在一些问题( hereherehere )。我尝试了这些链接中的所有建议,其中一些仍然保留在上面的 Dockerfile 中,但没有任何效果。在某种程度上,如果我来自干净的 Node 安装,那么我必须重建node-sass对我来说也是没有意义的。有什么建议吗?

最佳答案

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

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 install,但正如该标志所示,它是不安全的。更好的方法是关注 Starefossens best practices并创建另一个用户。

关于node.js - "Error: The ` libsass ` binding was not found..."在 Nodejs 4.2.4 lts 中,但在 5.4.1 中使用 docker,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34851308/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com