Heroku не использует кеш для Yarn v3
Попытка заставить Heroku использовать кэшированные модули для Yarn v3 с использованием рабочих пространств. Имею следующее:
:
"engines": {
"node": "16.x",
"yarn": "3.x"
},
"cacheDirectories": [
"node_modules",
"packages/components/node_modules",
"packages/lib/node_modules",
"packages/schema/node_modules",
"packages/web/node_modules",
"packages/web/.next/cache"
]
heroku-buildpack-features
:
cache-native-yarn-cache=true
Вывод Heroku:
-----> Creating runtime environment
NPM_CONFIG_LOGLEVEL=error
USE_YARN_CACHE=true
NODE_VERBOSE=false
NODE_ENV=production
NODE_MODULES_CACHE=true
-----> Installing binaries
! You don't need to specify Yarn engine. Heroku will install the latest Yarn 1.x, so that per project version can be used. More information here: https://yarnpkg.com/getting-started/install#global-install
https://devcenter.heroku.com/articles/nodejs-support
engines.node (package.json): 16.x
engines.npm (package.json): unspecified (use default)
engines.yarn (package.json): unspecified (use default)
Resolving node version 16.x...
Downloading and installing node 16.7.0...
Using default npm version: 7.20.3
Resolving yarn version 1.22.x...
Downloading and installing yarn (1.22.11)
Using yarn 3.0.0
-----> Installing binaries
! You don't need to specify Yarn engine. Heroku will install the latest Yarn 1.x, so that per project version can be used. More information here: https://yarnpkg.com/getting-started/install#global-install
https://devcenter.heroku.com/articles/nodejs-support
engines.node (package.json): 16.x
engines.npm (package.json): unspecified (use default)
engines.yarn (package.json): unspecified (use default)
Resolving node version 16.x...
Downloading and installing node 16.7.0...
Using default npm version: 7.20.3
Resolving yarn version 1.22.x...
Downloading and installing yarn (1.22.11)
Using yarn 3.0.0
-----> Restoring cache
Loading 6 from cacheDirectories (package.json):
- node_modules
- packages/components/node_modules (not cached - skipping)
- packages/lib/node_modules
- packages/schema/node_modules
- packages/web/node_modules
- packages/web/.next/cache
<a bunch of resolve stuff>
➤ YN0000: ┌ Fetch step
➤ YN0013: │ @apollo/client@npm:3.4.7 can't be found in the cache and will be fetched from the remote registry
➤ YN0013: │ @apollo/protobufjs@npm:1.2.2 can't be found in the cache and will be fetched from the remote registry
<and so on>
Я пробовал добавить
".yarn/cache"
к
cacheDirectories
в
package.json
, но он всегда говорит, что он пустой.
Не совсем уверен, куда идти дальше.
1 ответ
По состоянию на 9/2/2021, сборка Heroku nodeJS не полностью поддерживает yarn 2. Они начали добавлять поддержку в , но кэширование еще не было полностью v173решено .
Основная проблема заключается в том, что пакет сборки неправильно определяет это
$BUILD_DIR/.yarn/cache
существует и устанавливает для переменной среды значение, отличное от.(см. https://github.com/heroku/heroku-buildpack-nodejs/blob/752f1d5a139a800920cf5bb1bf70aad1a2954525/bin/compile#L140)
Когда пакет сборки переходит на этап кеширования, каталог на самом деле не существует.
Решение:
Мне удалось обойти это, установив вручную
YARN_CACHE_FOLDER
в конфигурацию vars. Вы можете сделать это через интерфейс командной строки, запустив
heroku config:set YARN_CACHE_FOLDER=.yarn/cache
.
Убедитесь, что вы также указали в cacheDirectories
.
Вы узнаете, что это работает, когда в журналах сборки отобразятся:
-----> Caching build
Saving 1 cacheDirectories (package.json):
- .yarn/cache
Если бы это не сработало, было бы
(nothing to cache)
примечание рядом с
.yarn/cache
.