首页 > 解决方案 > 在生产环境中运行 rails 6 项目时 CSS 关闭,但在开发环境中没有

问题描述

我正在开发一个在我的机器上运行良好的 Rails 项目。但是在 Heroku 上,一些 CSS 是关闭的。

这是我尝试过的。

我机器上的代码与 Heroku 服务器上的代码完全相同。我尝试将已编译的 CSS 文件从我的机器编译到 Heroku,并且它完全匹配。我已经修改了许多 development.rb 和 production.rb 设置,但无济于事。

当我rake assets:precompile在 Heroku 上运行时,我收到了一条有趣的消息:

autoprefixer:/app/app/assets/stylesheets/application.css:29539:3: Gradient has outdated direction syntax. New syntax is like 'closest-side at 0 0` instead of '0 0, closest-side'.

我能够通过运行复制问题(有时):rake assets:precompile RAILS_ENV=production

然后,如果我尝试启动服务器,我将获得 YARN 完整性

warning: warning Integrity check: Flags don't match error Integrity check failed error Found 1 errors.

您的 Yarn 包已过期!请运行yarn install --check-files更新。

我试图找出有关此错误的更多信息,但感觉不可能,运行“纱线检查 --integrity --verbose”我明白了

error Integrity check failed
verbose 0.656281167 Error: Found 1 errors.
    at MessageError.ExtendableBuiltin (/usr/share/yarn/lib/cli.js:721:66)
    at new MessageError (/usr/share/yarn/lib/cli.js:750:123)
    at /usr/share/yarn/lib/cli.js:61104:13
    at Generator.next (<anonymous>)
    at step (/usr/share/yarn/lib/cli.js:310:30)
    at /usr/share/yarn/lib/cli.js:321:13
error Found 1 errors.

当我运行“yarn install --check-files”时,我收到这个不是很有帮助的消息

yarn install v1.22.5
[1/4] Resolving packages...
[2/4] Fetching packages...
info fsevents@2.1.3: The platform "linux" is incompatible with this module.
info "fsevents@2.1.3" is an optional dependency and failed compatibility check. Excluding it from installation.
info fsevents@1.2.13: The platform "linux" is incompatible with this module.
info "fsevents@1.2.13" is an optional dependency and failed compatibility check. Excluding it from installation.
[3/4] Linking dependencies...
warning " > ts-loader@8.0.14" has unmet peer dependency "webpack@*".
warning " > webpack-dev-server@3.11.0" has unmet peer dependency "webpack@^4.0.0 || ^5.0.0".
warning "webpack-dev-server > webpack-dev-middleware@3.7.2" has unmet peer dependency "webpack@^4.0.0".
[4/4] Building fresh packages...
Done in 33.32s.

我最好的猜测是,由于某种原因,生产环境为某些依赖项触发了不同的版本,这导致一些 css 被错误地编译(顺便说一下使用 SASS)。

我不确定如何继续解决这个问题。我最好的猜测是预编译为生产并尝试修复 css 以适应它在 heroku 上的加载方式,但这似乎有点不对劲。任何想法都会非常有帮助。

标签: ruby-on-railsherokuwebpacksasscompilation

解决方案


推荐阅读