我在我的存储库中使用 Yarn Workspaces,还使用 AWS CodeBuild 构建我的包。构建开始时,CodeBuild 需要 60 秒来安装所有包,我想避免这次缓存
node_modules
文件夹。
当我添加:
cache:
paths:
- 'node_modules/**/*'
到我的
buildspec
文件并启用LOCAL_CUSTOM_CACHE
,我收到这个错误:
error 发生意外错误:“EEXIST:文件已经存在,mkdir '/codebuild/output/src637134264/src/git-codecommit.us-east-2.amazonaws.com/v1/repos/MY_REPOSITORY/node_modules/@packages/配置'”。
有没有办法消除配置 AWS CodeBuild 或 Yarn 时的这个错误?
我的构建规范文件:
version: 0.2
phases:
install:
commands:
- npm install -g yarn
- git config --global credential.helper '!aws codecommit credential-helper $@'
- git config --global credential.UseHttpPath true
- yarn
pre_build:
commands:
- git rev-parse HEAD
- git pull origin master
build:
commands:
- yarn run build
- yarn run deploy
post_build:
commands:
- echo 'Finished.'
cache:
paths:
- 'node_modules/**/*'
谢谢!
更新 1:
文件夹
/codebuild/output/src637134264/src/git-codecommit.us-east-2.amazonaws.com/v1/repos/MY_REPOSITORY/node_modules/@packages/configs
正在尝试由 Yarn 创建,在 - yarn
阶段使用命令 install
。该文件夹是我的存储库包之一,名为@packages/config
。当我在我的计算机上运行 yarn
时,Yarn 会创建链接我的包的文件夹,如 here 所述。我的node_modules
结构如何在我的计算机上的示例:
node_modules/
|-- ...
|-- @packages/
| |-- configs/
| |-- myPackageA/
| |-- myPackageB/
|-- ...
我遇到了完全相同的问题(“
EEXIST: file already exists, mkdir
”),我最终使用了 S3 缓存并且效果很好。 注意:由于某种原因,第一次上传到 S3 的时间(10 分钟)太长,其他的都很好。
之前:
[5/5] Building fresh packages...
--
Done in 60.28s.
之后:
[5/5] Building fresh packages...
--
Done in 6.64s.
如果您已经配置了项目,则可以编辑缓存访问项目 -> 编辑 -> 工件 -> 附加配置。
我的buildspec.yml如下:
version: 0.2
phases:
install:
runtime-versions:
nodejs: 14
build:
commands:
- yarn config set cache-folder /root/.yarn-cache
- yarn install --frozen-lockfile
- ...other build commands go here
cache:
paths:
- '/root/.yarn-cache/**/*'
- 'node_modules/**/*'
# This third entry is only if you're using monorepos (under the packages folder)
# - 'packages/**/node_modules/**/*'
如果你使用 NPM,你会做类似的事情,但命令略有不同:
version: 0.2
phases:
install:
runtime-versions:
nodejs: 14
build:
commands:
- npm config -g set prefer-offline true
- npm config -g set cache /root/.npm
- npm ci
- ...other build commands go here
cache:
paths:
- '/root/.npm-cache/**/*'
- 'node_modules/**/*'
# This third entry is only if you're using monorepos (under the packages folder)
# - 'packages/**/node_modules/**/*'
荣誉:https://mechanicalrock.github.io/2019/02/03/monorepos-aws-codebuild.html
如果有人在 2023 年仍然遇到这个错误,以下是我的一些观察:
如果您想使用任何类型的Local Cache(docker层,源缓存),它将与构建规范中的指定路径(用于自定义缓存)不兼容,例如
cache:
paths:
- 'node_modules'
您需要从构建规范中删除它。