因此,我正在尝试构建并发布一个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://learn.microsoft.com/azure/devops/pipelines/tasks/package/npm
2021-05-24T18:56:13.0038136Z ==============================================================================
2021-05-24T18:56:13.9312661Z [command]C:Windowssystem32cmd.exe /D /S /C "C:hostedtoolcachewindowsnode14.17.0x64npm.cmd --version"
2021-05-24T18:56:14.6978076Z 6.14.13
2021-05-24T18:56:16.3055204Z [command]C:Windowssystem32cmd.exe /D /S /C "C:hostedtoolcachewindowsnode14.17.0x64npm.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:npmprefixetcnpmrc
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:hostedtoolcachewindowsnode14.17.0x64node.exe
2021-05-24T18:56:17.0920510Z ; cwd = D:a1s
2021-05-24T18:56:17.0920984Z ; HOME = C:UsersVssAdministrator
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:Windowssystem32cmd.exe /D /S /C "C:hostedtoolcachewindowsnode14.17.0x64npm.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:npmcache_logs2021-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:npmcache_logs2021-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:hostedtoolcachewindowsnode14.17.0x64node_modulesnpmlibrun-script.js:155:19)
2021-05-24T18:56:18.0317478Z 4 verbose stack at C:hostedtoolcachewindowsnode14.17.0x64node_modulesnpmlibrun-script.js:63:5
2021-05-24T18:56:18.0318238Z 4 verbose stack at C:hostedtoolcachewindowsnode14.17.0x64node_modulesnpmnode_modulesread-package-jsonread-json.js:116:5
2021-05-24T18:56:18.0319056Z 4 verbose stack at C:hostedtoolcachewindowsnode14.17.0x64node_modulesnpmnode_modulesread-package-jsonread-json.js:436:5
2021-05-24T18:56:18.0319913Z 4 verbose stack at checkBinReferences_ (C:hostedtoolcachewindowsnode14.17.0x64node_modulesnpmnode_modulesread-package-jsonread-json.js:391:45)
2021-05-24T18:56:18.0322803Z 4 verbose stack at final (C:hostedtoolcachewindowsnode14.17.0x64node_modulesnpmnode_modulesread-package-jsonread-json.js:434:3)
2021-05-24T18:56:18.0323664Z 4 verbose stack at then (C:hostedtoolcachewindowsnode14.17.0x64node_modulesnpmnode_modulesread-package-jsonread-json.js:161:5)
2021-05-24T18:56:18.0324498Z 4 verbose stack at C:hostedtoolcachewindowsnode14.17.0x64node_modulesnpmnode_modulesread-package-jsonread-json.js:281:12
2021-05-24T18:56:18.0325369Z 4 verbose stack at C:hostedtoolcachewindowsnode14.17.0x64node_modulesnpmnode_modulesgraceful-fsgraceful-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:a1s
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
根据您的最新评论,bundle.js文件是有效的。
您可以尝试以下步骤来使用NPM任务运行js文件。
- 在Package.json文件中添加脚本参数
示例:
{
"name": "webpackguide",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "webpack-dev-server",
"bundle":"node bundle.js"
},
....
- 在NPM任务中,您可以直接调用bundle命令:
示例:
- task: Npm@1
displayName: 'npm custom'
inputs:
command: custom
workingDir: '$(System.DefaultWorkingDirectory)'
verbose: false
customCommand: 'run bundle'
好的,所以我将任务类型更改为命令行任务,并只调用node bundle.js:
steps:
- script: 'node bundle.js'
displayName: 'Bundle JS'