【问题标题】:"npm run build" error when building on VSTS/Azure DevOps在 VSTS/Azure DevOps 上构建时出现“npm run build”错误
【发布时间】:2019-07-20 12:28:30
【问题描述】:

我有一个 Vue 项目,它在我的机器上编译得很好。今天,我开始在 Azure DevOps 平台上进行部署设置,在调用“npm run build”之前,它似乎运行正常。从那里,我收到多个“ELIFECYCLE”错误,这对我没有多大帮助。 到目前为止我尝试过的:

  • 尝试使用npm clean cache 删除 node_modules 和 package-lock.json 并使用 cmd delete remove 命令
  • 在 Linux 和 Windows 生产机器上试用

我在这里错过了什么?

[command]C:\windows\system32\cmd.exe /D /S /C "C:\npm\prefix\npm.cmd run build"
-  Building for production...

 ERROR  Build failed with errors.
> appwork-vue-starter@1.2.1 build D:\_work\1\s
npm ERR! code ELIFECYCLE
> vue-cli-service build
npm ERR! errno 1

npm ERR! appwork-vue-starter@1.2.1 build: `vue-cli-service build`

npm ERR! Exit status 1
 ERROR  Failed to compile with 1 errors9:12:59 PM
npm ERR! 

npm ERR! Failed at the appwork-vue-starter@1.2.1 build script.
This relative module was not found:
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.


* ./Router in ./src/main.js
npm ERR! A complete log of this run can be found in:
npm ERR!     C:\npm\cache\_logs\2019-02-26T21_13_00_370Z-debug.log
Found npm debug log, make sure the path matches with the one in npm's output: C:\npm\cache\_logs\2019-02-26T21_13_00_370Z-debug.log
0 info it worked if it ends with ok
1 verbose cli [ 'C:\\Program Files\\nodejs\\node.exe',
1 verbose cli   'C:\\npm\\prefix\\node_modules\\npm\\bin\\npm-cli.js',
1 verbose cli   'run',
1 verbose cli   'build' ]
2 info using npm@6.7.0
3 info using node@v10.15.1
4 verbose run-script [ 'prebuild', 'build', 'postbuild' ]
5 info lifecycle appwork-vue-starter@1.2.1~prebuild: appwork-vue-starter@1.2.1
6 info lifecycle appwork-vue-starter@1.2.1~build: appwork-vue-starter@1.2.1
7 verbose lifecycle appwork-vue-starter@1.2.1~build: unsafe-perm in lifecycle true
8 verbose lifecycle appwork-vue-starter@1.2.1~build: PATH: C:\npm\prefix\node_modules\npm\node_modules\npm-lifecycle\node-gyp-bin;D:\_work\1\s\node_modules\.bin;C:\agents\2.147.1\externals\git\cmd;C:\Program Files\Git\bin;C:\Program Files\Git\usr\bin;C:\Program Files\Git\mingw64\bin;C:\Program Files\dotnet;C:\npm\prefix;C:\windows\system32;C:\windows;C:\windows\System32\Wbem;C:\windows\System32\WindowsPowerShell\v1.0\;C:\windows\System32\OpenSSH\;C:\ProgramData\Chocolatey\bin;C:\Users\packer\AppData\Local\Microsoft\WindowsApps;C:\Program Files\Docker;C:\Program Files\nodejs\;C:\Program Files\Git\cmd;C:\Program Files (x86)\Subversion\bin;C:\Users\VssAdministrator\AppData\Local\Microsoft\WindowsApps
9 verbose lifecycle appwork-vue-starter@1.2.1~build: CWD: D:\_work\1\s
10 silly lifecycle appwork-vue-starter@1.2.1~build: Args: [ '/d /s /c', 'vue-cli-service build' ]
11 silly lifecycle appwork-vue-starter@1.2.1~build: Returned: code: 1  signal: null
12 info lifecycle appwork-vue-starter@1.2.1~build: Failed to exec build script
13 verbose stack Error: appwork-vue-starter@1.2.1 build: `vue-cli-service build`
13 verbose stack Exit status 1
13 verbose stack     at EventEmitter.<anonymous> (C:\npm\prefix\node_modules\npm\node_modules\npm-lifecycle\index.js:301:16)
13 verbose stack     at EventEmitter.emit (events.js:189:13)
13 verbose stack     at ChildProcess.<anonymous> (C:\npm\prefix\node_modules\npm\node_modules\npm-lifecycle\lib\spawn.js:55:14)
13 verbose stack     at ChildProcess.emit (events.js:189:13)
13 verbose stack     at maybeClose (internal/child_process.js:970:16)
13 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:259:5)
14 verbose pkgid appwork-vue-starter@1.2.1
15 verbose cwd D:\_work\1\s
16 verbose Windows_NT 10.0.17134
17 verbose argv "C:\\Program Files\\nodejs\\node.exe" "C:\\npm\\prefix\\node_modules\\npm\\bin\\npm-cli.js" "run" "build"
18 verbose node v10.15.1
19 verbose npm  v6.7.0
20 error code ELIFECYCLE
21 error errno 1
22 error appwork-vue-starter@1.2.1 build: `vue-cli-service build`
22 error Exit status 1
23 error Failed at the appwork-vue-starter@1.2.1 build script.
23 error This is probably not a problem with npm. There is likely additional logging output above.
24 verbose exit [ 1, true ]

##[error]Error: Npm failed with return code: 1
##[section]Finishing: npm run build

【问题讨论】:

  • 您找到解决方案了吗?

标签: azure vue.js npm tfs azure-devops


【解决方案1】:

最后还是“./Router”下的case问题。仔细一看,日志中写道:

This relative module was not found:
* ./Router in ./src/main.js

这里的第一个问题是这些行在日志文件中没有相互跟随,所以很难解释。

在我的机器上,“./Router”的名称是正确的,但在 repo 上它有一个小写字母,这混淆了构建过程。不过很难追踪。

【讨论】:

    【解决方案2】:

    虽然不是您问题的直接答案,但在处理 Azure DevOps 托管代理上的节点时,我发现我确实遇到了一些随机错误,因此我转而使用容器来构建这些(托管代理内部)以及我的所有错误走了:

    jobs:
      - job: build_server
        pool:
          vmImage: 'Ubuntu-16.04'
        steps:
        # build
        - script: |
            docker run -v $(Build.SourcesDirectory):/npm node:10.15 bash \
              -c "cd /npm && npm install && npm run web-build"
    
        # package
        - task: Docker@1
          inputs:
            containerregistrytype: 'Container Registry'
            dockerRegistryEndpoint: ${{ parameters.registryName }}
            imageName: ${{ format('clarity2/{0}/$(Build.SourceBranchName):$(Build.BuildNumber)', parameters.solutionName) }}
            includeLatestTag: true
            dockerFile: dockerfile
        - task: Docker@1
          inputs:
            containerregistrytype: 'Container Registry'
            dockerRegistryEndpoint: ${{ parameters.registryName }}
            imageName: ${{ format('clarity2/{0}/$(Build.SourceBranchName)', parameters.solutionName) }}
            command: push
    

    【讨论】:

    • 感谢您的帮助!在 DevOps 中很难跟踪这些日志,我可能有一天会使用您的解决方案
    猜你喜欢
    • 2021-08-10
    • 2021-03-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-02-02
    • 1970-01-01
    • 2022-06-16
    • 2022-01-23
    相关资源
    最近更新 更多