在VSTS / Azure DevOps上构建时出现“ npm run build”错误

时间:2019-02-26 21:26:57

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

我有一个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

2 个答案:

答案 0 :(得分:1)

虽然不是您问题的直接答案,但在与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

答案 1 :(得分:0)

最后,这是在“ ./Router”下的一个案件。仔细观察,日志显示:

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

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

在我的机器上,“ ./ Router”的名称正确,但是在存储库中它的名称是小写的,这混淆了构建过程。但是,很难追踪。