使用AWS CodeBuild进行npm安装时未创建node_modules目录

3
CodeBuild构建完成后,当我通过ssh进入我的环境时,我可以看到服务器应用程序的依赖已安装并在其node_modules中找到。然而,在客户端目录中,没有node_modules或build目录。在构建日志中,npm install --prefix client --production 看起来运行良好。
我的问题与此问题几乎完全相同,除了它涉及node_modules和build文件夹。
构建规范文件是否存在问题?这是它的内容(修改4:已更新) 。
version: 0.2

phases:
  install:
    commands:
      # upgrade AWS CLI
      - pip install --upgrade awscli
      # install Node 12
      - curl -sL https://deb.nodesource.com/setup_12.x | bash -
      - apt install nodejs

  pre_build:
    commands:
      # install server dependencies
      - npm install
  build:
    commands:
      # install client dependencies and build static files
      - npm install --prefix client && npm run build --prefix client

  post_build:
    commands:
      - ls -la
      - ls client -la

artifacts:
  files:
    - '**/*'

编辑 1:这是一个 npm install --prefix client 的代码构建日志示例:

Running command npm install --prefix client --production



> core-js@2.6.11 postinstall /codebuild/output/src133125934/src/client/node_modules/babel-runtime/node_modules/core-js
> node -e "try{require('./postinstall')}catch(e){}"

对于npm run build -prefix client

[Container] 2020/07/02 00:24:06 Entering phase BUILD
[Container] 2020/07/02 00:24:06 Running command npm run build --prefix client



> client@0.1.0 build /codebuild/output/src133125934/src/client
> react-scripts build



Creating an optimized production build...
Compiled successfully.



File sizes after gzip:



  144.95 KB  build/static/js/2.d25271aa.chunk.js
  23.22 KB   build/static/css/main.fe6e5073.chunk.css
  6.38 KB    build/static/js/main.8e99a285.chunk.js
  774 B      build/static/js/runtime-main.f63e6028.js

编辑2:构建后使用 ls 命令查看目录:

[Container] 2020/07/02 01:11:24 Entering phase POST_BUILD
[Container] 2020/07/02 01:11:24 Running command ls -la
total 136
drwxr-xr-x  12 root root  4096 Jul  2 01:09 .
drwxr-xr-x   3 root root  4096 Jul  2 01:09 ..
drwxr-xr-x   2 root root  4096 Jul  2 01:09 .ebextensions
-rw-rw-r--   1 root root   130 Jul  2 01:08 .gitignore
-rw-rw-r--   1 root root    16 Jul  2 01:08 .npmrc
-rw-rw-r--   1 root root    34 Jul  2 01:08 README.md
-rw-rw-r--   1 root root  1737 Jul  2 01:08 app.js
drwxr-xr-x   2 root root  4096 Jul  2 01:09 bin
-rw-rw-r--   1 root root   566 Jul  2 01:08 buildspec.yml
drwxr-xr-x   6 root root  4096 Jul  2 01:10 client
drwxr-xr-x   2 root root  4096 Jul  2 01:09 config
drwxr-xr-x   2 root root  4096 Jul  2 01:09 graphql
drwxr-xr-x   2 root root  4096 Jul  2 01:09 models
drwxr-xr-x 197 root root  4096 Jul  2 01:10 node_modules
-rw-rw-r--   1 root root 63888 Jul  2 01:08 package-lock.json
-rw-rw-r--   1 root root   814 Jul  2 01:08 package.json
drwxr-xr-x   2 root root  4096 Jul  2 01:09 routes
drwxr-xr-x   2 root root  4096 Jul  2 01:09 services
drwxr-xr-x   2 root root  4096 Jul  2 01:09 views




[Container] 2020/07/02 01:11:24 Running command ls client -la
total 748
drwxr-xr-x    6 root root   4096 Jul  2 01:10 .
drwxr-xr-x   12 root root   4096 Jul  2 01:09 ..
drwxr-xr-x    3 root root   4096 Jul  2 01:11 build
drwxr-xr-x 1081 root root  36864 Jul  2 01:10 node_modules
-rw-rw-r--    1 root root 699332 Jul  2 01:08 package-lock.json
-rw-rw-r--    1 root root   1212 Jul  2 01:08 package.json
drwxr-xr-x    2 root root   4096 Jul  2 01:09 public
drwxr-xr-x    8 root root   4096 Jul  2 01:09 src

编辑3: 验证目录是否创建后,我通过ssh登录beanstalk(ec2)实例以检查它们是否已部署,但我得到了以下结果:

$ cd /var/app/current
$ ls
app.js
bin
buildspec.yml
client
config
graphql
models
node_modules
package.json
package-lock.json
Procfile
README.md
routes
services
views

$ cd client
$ ls
package.json 
package-lock.json 
public 
src


构建和模块目录没有部署到Beanstalk中。

但是 node_modules 是否存在或仍然缺失? - Marcin
还有 .ebextensions 呢?也许你在那里有一些脚本会删除或覆盖你的文件夹/文件? - Marcin
@Marcin 根目录中的 node_modules 一直都正常,但是在 client 文件夹中的那个以及 build 文件夹在构建后从未出现过。我会尝试暂时删除 .ebextensions 文件夹,看是否有任何变化。它只有一个名为 static-files.config 的文件,用于将静态文件设置到 client/build 中。这可能会影响它吗? - Justin Santer
@Marcin 删除 .ebextensions 没有任何变化,目录仍然不存在。这可能是某种缓存问题吗?这可能是一个“ .gitignore ”的问题吗?我已经忽略了两个“ node_module ”文件夹,但这并不能阻止根目录被创建。 - Justin Santer
不清楚。目前只是通过“尝试和查看”方法进行故障排除 :-( 我目前没有更精确的想法。抱歉。 - Marcin
显示剩余17条评论
1个回答

1
问题在于CodePipeline的部署阶段使用的是源码输出,而不是构建输出。将部署输入设置为构建输出即可解决此问题!

请问您能否将代码添加到这个解决方案中? - Luke

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接