【问题标题】:Heroku Review App not caching node_modulesHeroku Review App 不缓存 node_modules
【发布时间】:2020-03-08 05:36:46
【问题描述】:

我使用以下构建包:heroku-buildpack-nodejs 默认情况下,它应该缓存和恢复node_modules

yarn.lock 文件与package.json 一起位于应用程序的根目录。

我还添加了"cacheDirectories": [".cache/yarn"]package.json

在 review-app 构建日志分析期间,我看到:

-----> Restoring cache
Loading 1 from cacheDirectories (package.json):
- .cache/yarn (not cached - skipping)

...

-----> Installing dependencies
       Installing node modules (yarn.lock)

...

-----> Caching build
       - node_modules

似乎这个问题是在 2016 年 12 月 20 日打开的: https://github.com/heroku/heroku-buildpack-nodejs/issues/359

如何在不为每个构建安装依赖项的情况下实现缓存机制?

【问题讨论】:

    标签: node.js heroku npm yarnpkg buildpack


    【解决方案1】:

    Heroku NodeJS 构建包的v83 不支持使用 yarn 安装依赖项。这是在v93 中添加的。

    Buildpack v93 并非没有问题。因为它将相对于$build_diryarn cache path 硬编码为$build_dir/.cache/yarn/v2。 这会带来一个问题,因为 $build_dir 是一个临时目录,不能依赖它存在于下一次部署中。

    为了演示这一点,添加一个heroku-postbuildheroku-prebuild 命令脚本,用于scripts 中的package.json 键以显示正在运行的文件夹部署。

    "heroku-postbuild": "pwd"
    

    构建日志的部分输出

    remote:        $ echo 'postbuild'; pwd
    remote:        postbuild
    remote:        /tmp/build_260cb9d4ad95c7671332f8a404117b59
    remote:        Done in 0.10s.
    

    在后续版本的 buildpack 中解决了有关 yarn 部署的一些问题。我建议使用最新的构建包,目前是v165

    在 v165 中,the cache is copied from the temporary folder 将依赖项缓存到为 cacheDirectories 配置的依赖项,package.json 中的键

    目前,此功能位于功能标志后面。

    为了在您的部署中启用它,请在您的项目中创建一个features 文件。

    .
    ├── README.md
    ├── features
    ├── package.json
    └── yarn.lock
    

    features 文件中,写入

    cache-native-yarn-cache=true
    

    重新运行您的部署应该会产生类似于以下内容的日志:

    remote:
    remote: -----> Restoring cache
    remote:        Loading 1 from cacheDirectories (package.json):
    remote:        - .cache/yarn
    

    【讨论】:

    • Oluwafemi 它不工作,我仍然得到: - .yarn_cache(未缓存 - 跳过)
    猜你喜欢
    • 1970-01-01
    • 2018-10-03
    • 2015-06-16
    • 1970-01-01
    • 1970-01-01
    • 2021-07-12
    • 1970-01-01
    • 2020-07-15
    • 2018-08-23
    相关资源
    最近更新 更多