简体   繁体   English

Rails 5 + Webpacker应用程序部署到Heroku作为空白页面,没有失败

[英]Rails 5 + Webpacker app deploys to Heroku as blank page with no failures

I have a straightforward Rails 5.1 app that uses Webpacker and Vue.js. 我有一个简单的Rails 5.1应用程序,它使用Webpacker和Vue.js. It works perfectly in development with webpack-dev-server . 它在webpack-dev-server开发中非常webpack-dev-server When I push to the Heroku repository it completes with no errors and nothing seemingly out of the ordinary. 当我推送到Heroku存储库时,它完成没有任何错误,看起来没有任何异常。 The HTML page renders but the <div id="app"> element where the Vue.js app is supposed to be rendered is replaced only by a comment: HTML页面呈现但是应该呈现Vue.js应用程序的<div id="app">元素仅由注释替换:

<!--function (e,n,r,o){return on(t,e,n,r,o,!0)}-->

The JavaScript pack file is indeed there and I looked at it and it seems to be all correct. JavaScript包文件确实在那里,我看着它,它似乎都是正确的。

I tried replacing the normal Ruby buildpack with a Node.js Buildpack followed by a Ruby Buildpack but to no avail. 我尝试使用Node.js Buildpack替换正常的Ruby buildpack,然后使用Ruby Buildpack替换,但无济于事。 This is the full Heroku deploy log: 这是完整的Heroku部署日志:

-----> Node.js app detected
-----> Creating runtime environment

       NPM_CONFIG_LOGLEVEL=error
       NPM_CONFIG_PRODUCTION=true
       NODE_VERBOSE=false
       NODE_ENV=production
       NODE_MODULES_CACHE=true
-----> Installing binaries
       engines.node (package.json):  unspecified
       engines.npm (package.json):   unspecified (use default)
       engines.yarn (package.json):  unspecified (use default)

       Resolving node version 8.x...
       Downloading and installing node 8.9.4...
       Using default npm version: 5.6.0
       Resolving yarn version 1.x...
       Downloading and installing yarn (1.4.0)...
       Installed yarn 1.4.0
-----> Restoring cache
       Skipping cache restore (not-found)
-----> Building dependencies
       Installing node modules (yarn.lock)
       yarn install v1.4.0
       [1/4] Resolving packages...
       [2/4] Fetching packages...
       info fsevents@1.1.3: The platform "linux" is incompatible with this module.
       info "fsevents@1.1.3" is an optional dependency and failed compatibility check. Excluding it from installation.
       [3/4] Linking dependencies...
       warning "@rails/webpacker > postcss-cssnext@3.1.0" has unmet peer dependency "caniuse-lite@^1.0.30000697".
       warning " > vue-loader@13.7.1" has unmet peer dependency "css-loader@*".
       warning " > webpack-dev-server@2.11.1" has unmet peer dependency "webpack@^2.2.0 || ^3.0.0".
       warning "webpack-dev-server > webpack-dev-middleware@1.12.2" has unmet peer dependency "webpack@^1.0.0 || ^2.0.0 || ^3.0.0".
       [4/4] Building fresh packages...
       Done in 20.38s.
-----> Caching build
       Clearing previous node cache
       Saving 2 cacheDirectories (default):
       - node_modules
       - bower_components (nothing to cache)
-----> Build succeeded!
 !     Unmet dependencies don't fail yarn install but may cause runtime issues
       https://github.com/npm/npm/issues/7494
-----> Ruby app detected
-----> Compiling Ruby/Rails
-----> Using Ruby version: ruby-2.5.0
-----> Installing dependencies using bundler 1.15.2
       Running: bundle install --without development:test --path vendor/bundle --binstubs vendor/bundle/bin -j4 --deployment
       Warning: the running version of Bundler (1.15.2) is older than the version that created the lockfile (1.16.1). We suggest you upgrade to the latest version of Bundler by running `gem install bundler`.
       Fetching gem metadata from https://rubygems.org/.........
       Fetching version metadata from https://rubygems.org/..
       Fetching dependency metadata from https://rubygems.org/.
       Using rake 12.3.0
       Using concurrent-ruby 1.0.5
       Using minitest 5.11.3
       Using thread_safe 0.3.6
       Using builder 3.2.3
       Using erubi 1.7.0
       Using mini_portile2 2.3.0
       Using crass 1.0.3
       Using rack 2.0.4
       Using nio4r 2.2.0
       Using websocket-extensions 0.1.3
       Using mini_mime 1.0.0
       Using arel 8.0.0
       Using execjs 2.7.0
       Using bundler 1.15.2
       Using ffi 1.9.18
       Using multi_json 1.13.1
       Using method_source 0.9.0
       Using pg 0.21.0
       Using puma 3.11.2
       Using thor 0.20.0
       Using rb-fsevent 0.10.2
       Using redcarpet 3.4.0
       Using tilt 2.0.8
       Using temple 0.8.0
       Using yard 0.9.12
       Using i18n 0.9.3
       Using tzinfo 1.2.5
       Using nokogiri 1.8.2
       Using rack-test 0.8.2
       Using rack-proxy 0.6.3
       Using sprockets 3.7.1
       Using autoprefixer-rails 7.2.5
       Using mail 2.7.0
       Using websocket-driver 0.6.5
       Using rb-inotify 0.9.10
       Using activesupport 5.1.4
       Using slim 3.0.9
       Using loofah 2.1.1
       Using sass-listen 4.0.0
       Using rails-dom-testing 2.0.3
       Using globalid 0.4.1
       Using activemodel 5.1.4
       Using jbuilder 2.7.0
       Using rails-html-sanitizer 1.0.3
       Using sass 3.5.5
       Using activerecord 5.1.4
       Using activejob 5.1.4
       Using actionview 5.1.4
       Using actionpack 5.1.4
       Using actioncable 5.1.4
       Using railties 5.1.4
       Using sprockets-rails 3.2.1
       Using actionmailer 5.1.4
       Using responders 2.4.0
       Using sass-rails 5.0.7
       Using slim-rails 3.1.3
       Using webpacker 3.2.1
       Using rails 5.1.4
       Bundle complete! 22 Gemfile dependencies, 59 gems now installed.
       Gems in the groups development and test were not installed.
       Bundled gems are installed into ./vendor/bundle.
       Bundle completed (2.81s)
       Cleaning up the bundler cache.
       Warning: the running version of Bundler (1.15.2) is older than the version that created the lockfile (1.16.1). We suggest you upgrade to the latest version of Bundler by running `gem install bundler`.
       The latest bundler is 1.16.1, but you are currently running 1.15.2.
       To update, run `gem install bundler`
-----> Detecting rake tasks
-----> Preparing app for Rails asset pipeline
       Running: rake assets:precompile
       yarn install v1.4.0
       [1/4] Resolving packages...
       [2/4] Fetching packages...
       info fsevents@1.1.3: The platform "linux" is incompatible with this module.
       info "fsevents@1.1.3" is an optional dependency and failed compatibility check. Excluding it from installation.
       [3/4] Linking dependencies...
       warning "@rails/webpacker > postcss-cssnext@3.1.0" has unmet peer dependency "caniuse-lite@^1.0.30000697".
       warning " > vue-loader@13.7.1" has unmet peer dependency "css-loader@*".
       warning " > webpack-dev-server@2.11.1" has unmet peer dependency "webpack@^2.2.0 || ^3.0.0".
       warning "webpack-dev-server > webpack-dev-middleware@1.12.2" has unmet peer dependency "webpack@^1.0.0 || ^2.0.0 || ^3.0.0".
       [4/4] Building fresh packages...
       Done in 21.12s.
       Webpacker is installed 🎉 🍰
       Using /tmp/build_d85ffa3d23df7c297f570fcf78860053/config/webpacker.yml file for setting up webpack paths
       Compiling…
       Compiled all packs in /tmp/build_d85ffa3d23df7c297f570fcf78860053/public/packs
       Asset precompilation completed (44.22s)
       Cleaning assets
       Running: rake assets:clean
-----> Discovering process types
       Procfile declares types     -> hot, web
       Default types for buildpack -> console, rake, worker
-----> Compressing...
       Done: 70.3M
-----> Launching...
       Released v12
       https://tbm-budget.herokuapp.com/ deployed to Heroku

This ended up being a problem with my Vue runtime configuration. 这最终成为我的Vue运行时配置的问题。 As you may know, if you're using vue-loader with Webpack, your Vue templates are precompiled into render functions. 您可能知道,如果您在Webpack中使用vue-loader,则Vue模板会预编译为渲染函数。 Then you do not have to load the Vue runtime in production because no templates are compiled on-the-fly (like they typically are in development). 然后,您不必在生产中加载Vue运行时,因为没有模板是即时编译的(就像它们通常在开发中一样)。

The problem was my Vue bootstrap code which creates and mounts the root element. 问题是我的Vue引导程序代码,它创建并安装了根元素。 I was calling new Vue({el: '#app', ...}) (with <div id="app"><my-content-here /></div> ), but that in itself is an uncompiled template and won't work in production. 我正在调用new Vue({el: '#app', ...}) (使用<div id="app"><my-content-here /></div> ),但这本身就是一个未编译的模板,不会在生产中工作。

The solution was instead to write a precompiled template with its own render function, and mount that: new Vue({render: function() { ... }}).$mount(document.getElementByID('app')) . 解决方案是使用自己的渲染函数编写预编译模板,然后安装: new Vue({render: function() { ... }}).$mount(document.getElementByID('app')) In my case I just created a very simple .vue file that contains the root <router-view> div (for Vue-Router), import ed that, and $mount ed it. 在我的情况下,我刚刚创建了一个非常简单的.vue文件,其中包含根<router-view> div(对于Vue-Router), import ed和$mount ed。

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

相关问题 MERN 应用部署到 heroku,一个空白页面 - MERN app deploying to heroku, a blank page Rails:Webpacker 4.2 在 /app/public/packs/manifest.json heroku 中找不到应用程序 - Rails: Webpacker 4.2 can't find application in /app/public/packs/manifest.json heroku 仅当页面加载到 Rails 应用程序上时,如何运行 webpacker 编译的 javascript? - How to run webpacker compiled javascript only when page is loaded on rails app? create-react-app 部署在 Heroku 但页面为空白 - create-react-app is deployed on Heroku but page is blank webpacker在heroku上无法正常工作 - webpacker not working correctly on heroku Rails、Webpacker 和 Turbolinks - Javascript 在离开页面或完全重新加载之前不加载 - Rails, Webpacker and Turbolinks - Javascript not loading until leaving the page, or full reload 为新 Rails 应用程序运行服务器时出现 Webpacker 错误 - Webpacker error when running server for new Rails app 使用Webpacker在Rails应用程序中渲染ReactJS CRUD组件问题 - Issue rendering ReactJS CRUD components in Rails app with Webpacker 在使用 rails/webpacker 的 vue 应用程序中使用 vuetify 自定义 sass 变量 - Using vuetify custom sass variables in a vue app using rails/webpacker QuerySelector 在 Rails Webpacker 中不起作用 - QuerySelector Not Working in Rails Webpacker
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM