在Rails资产中获取错误:使用Webpacker和Heroku管道

时间:2017-12-21 05:02:58

标签: ruby-on-rails heroku vuejs2 webpacker

我有一个Rails 5.1.4应用程序,我继承了部署到Heroku的应用程序。它正在使用带有vuejs的webpacker,现在我遇到了部署到Heroku的问题。当Heroku运行rake assets:precompile:

时,我收到以下消息
remote:        [13] ./app/javascript/production-guarantee-component.vue 193 bytes {0} [built] [failed] [1 error]
remote:        [14] ./app/javascript/packs/tmp_dashboard.js 2.44 kB {1} [built]
remote:        + 4 hidden modules
remote:        ERROR in ./app/javascript/adder-dashboard.vue
remote:        Module parse failed: Unexpected token (1:0)
remote:        You may need an appropriate loader to handle this file type.
remote:        | <template>
remote:        |   <div class="col-md-12">
remote:        |       <adder-component v-for="category in categories" :category ="category"></adder-component>
remote:        @ ./app/javascript/packs/pricing_dashboard.js 16:0-52
remote:        ERROR in ./app/javascript/app.vue
remote:        Module parse failed: Unexpected token (1:

代码在本地运行良好,而Module parse failed对我来说甚至没有意义。什么是调试的好地方?

1 个答案:

答案 0 :(得分:0)

通常会node_modules添加到.gitignore。我建议你在本地生产环境中测试你的应用程序。运行RAILS_ENV=production bundle exec rake assets:precompile以预编译生产中的资产。

如果要使用yarn安装js依赖项,则rails预编译也应该触发yarn install,然后运行生产服务器rails s -e production并在localenvironment中对其进行测试

此外,您需要从adder-dashboard.vue找到github存储库,并阅读有关使用带有rails的vue.js的文档

https://ksylvest.com/posts/2016-09-07/augmenting-a-ruby-on-rails-app-with-vue-js

https://rlafranchi.github.io/2016/03/09/vuejs-and-rails/

Use Dropzone.js with Vue.js

https://coligo.io/real-time-analytics-with-nodejs-socketio-vuejs/