【问题标题】:Rails Simple Blogger Heroku App: Precompiling Assets FailedRails Simple Blogger Heroku App:预编译资产失败
【发布时间】:2020-04-17 09:07:03
【问题描述】:

我已经尝试了书中感觉的所有内容,但我一直遇到同样的错误。 令人惊讶的是,我在其他任何地方都没有发现这个确切的错误。


remote:        error Couldn't find a package.json file in "/tmp/build_0e5b0c14c98db4a63ddfc87fc6d11490"

Here is the full error on Pastebin

Here is the repository for the (rather simple) blogger project

我什至尝试在本地运行 rake assets:precompile 并且绝对没有遇到任何错误。 我跑了RAILS_ENV=production bundle exec rake assets:precompile,推送到我的仓库然后尝试部署,什么都没有。

我搜索了大量 StackOverflow 问题,并尝试在谷歌上搜索我的错误,尝试了我遇到的每个编辑/命令,但没有运气。

编辑:以下是我的 package.json 文件的内容

{
  "name": "blogger",
  "private": true,
  "dependencies": {
    "@rails/actioncable": "^6.0.0",
    "@rails/activestorage": "^6.0.0",
    "@rails/ujs": "^6.0.0",
    "@rails/webpacker": "4.2.2",
    "turbolinks": "^5.2.0"
  },
  "version": "0.1.0",
  "devDependencies": {
    "webpack-dev-server": "^3.10.1"
  }
}

【问题讨论】:

  • 在 rails 6 的 app 目录中有一个 package.json 文件。它正在查找该文件。
  • 我用我的 package.json 文件的内容更新了我的帖子,我不确定它有什么问题

标签: ruby-on-rails ruby heroku


【解决方案1】:

我的 package.json 文件不存在于我的 Github 存储库中,尽管它确实存在于我的本地系统中。

我没有待提交的文件,并且我的 .gitignore 显示没有排除任何 json 文件。 我不确定为什么它没有上传到我的存储库。

所以我不得不通过运行将其强制添加到暂存区: git add -f path/to/the/file(归功于@San's answer to a different question)。

然后我简单地提交了更改并成功推送到 Heroku!

【讨论】:

    【解决方案2】:

    Rails 6 的基本配置:-

    运行yarn install,或只运行yarn。它将创建一个 package.json 文件:-

    `package.json'

    此文件包含您的 webpack 所需的包。

    更多参考请阅读:-

    #yarn docs

    #webpacker

    如果您想在生产环境中预编译,请更改以下文件中的配置:-

    config/webpacker.yml
    
    production:
      <<: *default
    
      # Production depends on precompilation of packs prior to booting for performance.
      compile:true ## just make this compile true
    
      # Extract and emit a css file
      extract_css: true
    
      # Cache manifest.json for performance
      cache_manifest: true
    

    然后执行命令:-

    RAILS_ENV=production rake assets:clobber 
    RAILS_ENV=production rake assets:precompile
    

    【讨论】:

    • 我按照您的步骤操作,但我的应用程序已经有了一个 package.json 文件。我更新了我的帖子以显示其内容。无论如何,它都会给我同样的错误。
    • 感谢您的解释! :}
    • 但是在你的 git 仓库中没有 package.json 文件。
    • 需要上传吗?它不在我的 .gitignore 或任何东西中。 i.postimg.cc/VNNQwVmh/Screenshot-2019-12-28-23-11-34.png
    • 以上是我的项目回购截图你必须做同样的事情推送你的 package.json 文件。因为错误你可以清楚地看到 heroku 正在寻找 package.json 文件。谢谢和你也赞成我的回答..它不花钱:)
    猜你喜欢
    • 2021-11-12
    • 2014-06-27
    • 1970-01-01
    • 1970-01-01
    • 2012-11-29
    • 1970-01-01
    • 2023-04-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多