首页 > 解决方案 > 用于构建 Angular JS 应用程序包的 Azure 管道失败 - npm ERR!缺少脚本:D:\a\1\s/bundle.js

问题描述

所以我正在尝试构建一个 angular.js 应用程序并将其发布到 azure blob 存储。我有项目构建,我现在需要运行捆绑任务来创建我想要发布到 blob 存储的输出,但是当我运行任务时,我得到:npm ERR!缺少脚本:D:\a\1\s/bundle.js

有问题的构建步骤是一个 NPM 任务,并且有这个 YAML :

    - task: Npm@1
  displayName: 'npm bundle'
  inputs:
    command: custom
    workingDir: '$(System.DefaultWorkingDirectory)'
    verbose: false
    customCommand: 'run $(System.DefaultWorkingDirectory)/bundle.js'

知道我如何进行捆绑吗?

这是任务的输出:

    2021-05-24T18:56:12.9880011Z ##[section]Starting: npm bundle
2021-05-24T18:56:13.0035645Z ==============================================================================
2021-05-24T18:56:13.0036045Z Task         : npm
2021-05-24T18:56:13.0036457Z Description  : Install and publish npm packages, or run an npm command. Supports npmjs.com and authenticated registries like Azure Artifacts.
2021-05-24T18:56:13.0036887Z Version      : 1.182.0
2021-05-24T18:56:13.0037154Z Author       : Microsoft Corporation
2021-05-24T18:56:13.0037500Z Help         : https://docs.microsoft.com/azure/devops/pipelines/tasks/package/npm
2021-05-24T18:56:13.0038136Z ==============================================================================
2021-05-24T18:56:13.9312661Z [command]C:\Windows\system32\cmd.exe /D /S /C "C:\hostedtoolcache\windows\node\14.17.0\x64\npm.cmd --version"
2021-05-24T18:56:14.6978076Z 6.14.13
2021-05-24T18:56:16.3055204Z [command]C:\Windows\system32\cmd.exe /D /S /C "C:\hostedtoolcache\windows\node\14.17.0\x64\npm.cmd config list"
2021-05-24T18:56:17.0914358Z ; cli configs
2021-05-24T18:56:17.0915201Z metrics-registry = "https://registry.npmjs.org/"
2021-05-24T18:56:17.0915747Z scope = ""
2021-05-24T18:56:17.0916249Z user-agent = "npm/6.14.13 node/v14.17.0 win32 x64"
2021-05-24T18:56:17.0916554Z 
2021-05-24T18:56:17.0916973Z ; environment configs
2021-05-24T18:56:17.0917440Z prefix = "C:\\npm\\prefix"
2021-05-24T18:56:17.0917914Z userconfig = "D:\\a\\1\\npm\\642.npmrc"
2021-05-24T18:56:17.0918226Z 
2021-05-24T18:56:17.0918651Z ; globalconfig C:\npm\prefix\etc\npmrc
2021-05-24T18:56:17.0919191Z cache = "C:\\npm\\cache"
2021-05-24T18:56:17.0919472Z 
2021-05-24T18:56:17.0919966Z ; node bin location = C:\hostedtoolcache\windows\node\14.17.0\x64\node.exe
2021-05-24T18:56:17.0920510Z ; cwd = D:\a\1\s
2021-05-24T18:56:17.0920984Z ; HOME = C:\Users\VssAdministrator
2021-05-24T18:56:17.0921466Z ; "npm config ls -l" to show all defaults.
2021-05-24T18:56:17.0921829Z 
2021-05-24T18:56:17.0924582Z [command]C:\Windows\system32\cmd.exe /D /S /C "C:\hostedtoolcache\windows\node\14.17.0\x64\npm.cmd run bundle.js"
2021-05-24T18:56:17.9822327Z npm ERR! missing script: bundle.js
2021-05-24T18:56:17.9822972Z 
2021-05-24T18:56:17.9823559Z npm ERR! A complete log of this run can be found in:
2021-05-24T18:56:17.9825738Z npm ERR!     C:\npm\cache\_logs\2021-05-24T18_56_17_954Z-debug.log
2021-05-24T18:56:18.0311838Z Found npm debug log, make sure the path matches with the one in npm's output: C:\npm\cache\_logs\2021-05-24T18_56_17_954Z-debug.log
2021-05-24T18:56:18.0312533Z 0 info it worked if it ends with ok
2021-05-24T18:56:18.0312918Z 1 verbose cli [
2021-05-24T18:56:18.0313463Z 1 verbose cli   'C:\\hostedtoolcache\\windows\\node\\14.17.0\\x64\\node.exe',
2021-05-24T18:56:18.0314045Z 1 verbose cli   'C:\\hostedtoolcache\\windows\\node\\14.17.0\\x64\\node_modules\\npm\\bin\\npm-cli.js',
2021-05-24T18:56:18.0314505Z 1 verbose cli   'run',
2021-05-24T18:56:18.0314812Z 1 verbose cli   'bundle.js'
2021-05-24T18:56:18.0315127Z 1 verbose cli ]
2021-05-24T18:56:18.0315491Z 2 info using npm@6.14.13
2021-05-24T18:56:18.0315798Z 3 info using node@v14.17.0
2021-05-24T18:56:18.0316183Z 4 verbose stack Error: missing script: bundle.js
2021-05-24T18:56:18.0316777Z 4 verbose stack     at run (C:\hostedtoolcache\windows\node\14.17.0\x64\node_modules\npm\lib\run-script.js:155:19)
2021-05-24T18:56:18.0317478Z 4 verbose stack     at C:\hostedtoolcache\windows\node\14.17.0\x64\node_modules\npm\lib\run-script.js:63:5
2021-05-24T18:56:18.0318238Z 4 verbose stack     at C:\hostedtoolcache\windows\node\14.17.0\x64\node_modules\npm\node_modules\read-package-json\read-json.js:116:5
2021-05-24T18:56:18.0319056Z 4 verbose stack     at C:\hostedtoolcache\windows\node\14.17.0\x64\node_modules\npm\node_modules\read-package-json\read-json.js:436:5
2021-05-24T18:56:18.0319913Z 4 verbose stack     at checkBinReferences_ (C:\hostedtoolcache\windows\node\14.17.0\x64\node_modules\npm\node_modules\read-package-json\read-json.js:391:45)
2021-05-24T18:56:18.0322803Z 4 verbose stack     at final (C:\hostedtoolcache\windows\node\14.17.0\x64\node_modules\npm\node_modules\read-package-json\read-json.js:434:3)
2021-05-24T18:56:18.0323664Z 4 verbose stack     at then (C:\hostedtoolcache\windows\node\14.17.0\x64\node_modules\npm\node_modules\read-package-json\read-json.js:161:5)
2021-05-24T18:56:18.0324498Z 4 verbose stack     at C:\hostedtoolcache\windows\node\14.17.0\x64\node_modules\npm\node_modules\read-package-json\read-json.js:281:12
2021-05-24T18:56:18.0325369Z 4 verbose stack     at C:\hostedtoolcache\windows\node\14.17.0\x64\node_modules\npm\node_modules\graceful-fs\graceful-fs.js:123:16
2021-05-24T18:56:18.0326349Z 4 verbose stack     at FSReqCallback.readFileAfterClose [as oncomplete] (internal/fs/read_file_context.js:73:3)
2021-05-24T18:56:18.0326818Z 5 verbose cwd D:\a\1\s
2021-05-24T18:56:18.0327158Z 6 verbose Windows_NT 10.0.17763
2021-05-24T18:56:18.0327803Z 7 verbose argv "C:\\hostedtoolcache\\windows\\node\\14.17.0\\x64\\node.exe" "C:\\hostedtoolcache\\windows\\node\\14.17.0\\x64\\node_modules\\npm\\bin\\npm-cli.js" "run" "bundle.js"
2021-05-24T18:56:18.0328421Z 8 verbose node v14.17.0
2021-05-24T18:56:18.0328745Z 9 verbose npm  v6.14.13
2021-05-24T18:56:18.0329098Z 10 error missing script: bundle.js
2021-05-24T18:56:18.0329457Z 11 verbose exit [ 1, true ]
2021-05-24T18:56:18.0329605Z 
2021-05-24T18:56:18.0372730Z ##[error]Error: Npm failed with return code: 1
2021-05-24T18:56:18.0394696Z ##[section]Finishing: npm bundle

标签: angularjsazure-devopsazure-pipelines

解决方案


根据您的最新评论,bundle.js 文件是有效的。

您可以尝试以下步骤来使用 NPM 任务运行 js 文件。

  1. 在 Package.json 文件中添加脚本参数。

例子:

{
  "name": "webpackguide",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "start": "webpack-dev-server",
    "bundle":"node bundle.js"
  },

....
  1. 在 NPM 任务中,你可以直接调用 bundle 命令:

例子:

- task: Npm@1
  displayName: 'npm custom'
  inputs:
    command: custom
    workingDir: '$(System.DefaultWorkingDirectory)'
    verbose: false
    customCommand: 'run bundle'

推荐阅读