【问题标题】:jest: not found after npm install on Azure pipeline开玩笑:在 Azure 管道上安装 npm 后找不到
【发布时间】:2026-01-04 19:40:01
【问题描述】:

问题

我在 Azure 上运行此管道文件,但我发现找不到包。在使用 npm install 安装软件包后,我想使用 Jest 和命令 npm test 运行测试。 Jest 在 package.json 的 devDependencies 中,我认为这就是它没有开始安装在 azure 上的原因。

sh: 1: jest: not found

pipeline.yaml:

parameters:
  triggerType: ''

jobs:
- job: RunTests 
  pool:
    vmImage: 'ubuntu-latest'
  steps:
  - task: NodeTool@0
    inputs:
      versionSpec: '10.x'
    displayName: 'Install Node.js'
  - script: |
      npm install -registry [[[[https://myregistryurl]]]]
    displayName: 'npm install'
  - script: npm test
    displayName: 'npm test'

package.json

{
  "name": "ssu-dashboard-client",
  "version": "2.3.1",
  "description": "Dashboard for operation planning",
  "main": "server.js",
  "author": "Olavstoppen",
  "repository": {},
  "license": "MIT",
  "scripts": {
    "dev": "cross-env NODE_ENV=development nodemon --watch webpack.config.js --watch server.js",
    "dev:inspect": "cross-env NODE_ENV=development nodemon --inspect server.js ",
    "build": "cross-env NODE_ENV=production webpack --mode production",
    "start": "cross-env NODE_ENV=production node server.js",
    "test": "jest"
  },
  "dependencies": {
    "@babel/preset-flow": "^7.12.1",
    "applicationinsights-js": "^1.0.20",
    "axios": "^0.18.1",
    "babel-jest": "^26.6.3",
    "babel-preset-jest": "^26.6.2",
    "color": "^3.1.1",
    "connected-react-router": "^6.4.0",
    "d3": "^5.9.2",
    "date-fns": "^2.12.0",
    "date-fns-tz": "^1.0.10",
    "highcharts": "7.1.2",
    "highcharts-drilldown": "^0.1.7",
    "highcharts-more": "^0.1.7",
    "highcharts-react-official": "^2.2.2",
    "history": "^4.9.0",
    "prop-types": "^15.7.2",
    "ramda": "^0.26.1",
    "react": "^16.8.6",
    "react-dom": "^16.8.6",
    "react-google-charts": "^2.0.29",
    "react-highcharts": "^16.0.2",
    "react-is": "^16.13.1",
    "react-json-tree": "^0.11.2",
    "react-measure": "^2.3.0",
    "react-redux": "^7.0.3",
    "react-router": "^5.0.0",
    "react-router-dom": "^5.0.0",
    "react-router-hash-link": "^1.2.1",
    "react-saga": "^0.2.6",
    "redux": "^4.0.1",
    "redux-logger": "^3.0.6",
    "redux-saga": "^0.16.2",
    "redux-thunk": "^2.3.0",
    "reselect": "^4.0.0",
    "sanitize-html": "^2.1.2",
    "styled-components": "^5.2.1",
    "styled-system": "^5.1.5",
    "tinymce": "^5.4.2"
  },
  "devDependencies": {
    "@babel/core": "^7.4.4",
    "@babel/plugin-proposal-class-properties": "^7.12.1",
    "@babel/plugin-proposal-decorators": "^7.4.4",
    "@babel/plugin-proposal-export-namespace-from": "^7.2.0",
    "@babel/plugin-proposal-function-sent": "^7.2.0",
    "@babel/plugin-proposal-json-strings": "^7.2.0",
    "@babel/plugin-proposal-numeric-separator": "^7.2.0",
    "@babel/plugin-proposal-throw-expressions": "^7.2.0",
    "@babel/plugin-syntax-dynamic-import": "^7.8.3",
    "@babel/plugin-syntax-import-meta": "^7.2.0",
    "@babel/plugin-transform-runtime": "^7.4.4",
    "@babel/polyfill": "^7.4.4",
    "@babel/preset-env": "^7.12.1",
    "@babel/preset-react": "^7.12.5",
    "@hot-loader/react-dom": "^16.8.6",
    "@svgr/webpack": "^4.2.0",
    "@testing-library/jest-dom": "^5.11.6",
    "@testing-library/react": "^11.1.2",
    "adal-node": "^0.1.28",
    "applicationinsights": "^1.3.1",
    "babel-eslint": "^10.0.1",
    "babel-loader": "^8.0.5",
    "babel-plugin-dynamic-import-node": "^2.3.3",
    "babel-plugin-import": "^1.11.0",
    "babel-plugin-styled-components": "^1.10.0",
    "body-parser": "^1.19.0",
    "connect-logger": "0.0.1",
    "cookie-parser": "^1.4.4",
    "cookie-session": "^2.0.0-beta.3",
    "copy-webpack-plugin": "^4.6.0",
    "core-js": "^3.0.1",
    "cross-env": "^5.2.0",
    "css-loader": "^1.0.1",
    "dotenv": "^6.2.0",
    "dotenv-webpack": "^1.7.0",
    "eslint": "^5.16.0",
    "eslint-config-airbnb": "^17.1.0",
    "eslint-config-prettier": "^3.6.0",
    "eslint-config-standard": "^12.0.0",
    "eslint-plugin-import": "^2.17.2",
    "eslint-plugin-jsx-a11y": "^6.2.1",
    "eslint-plugin-node": "^7.0.1",
    "eslint-plugin-promise": "^4.1.1",
    "eslint-plugin-react": "^7.12.4",
    "eslint-plugin-standard": "^4.0.0",
    "eslint-plugin-styled-components-config": "^0.0.2",
    "express": "^4.16.4",
    "extract-text-webpack-plugin": "^4.0.0-beta.0",
    "file-loader": "^2.0.0",
    "helmet": "^3.16.0",
    "html-webpack-plugin": "^3.0.7",
    "identity-obj-proxy": "^3.0.0",
    "jest": "^26.6.3",
    "jest-styled-components": "^7.0.3",
    "jest-svg-transformer": "^1.0.0",
    "node-sass": "^4.13.0",
    "nodemon": "^1.19.0",
    "postcss-loader": "^3.0.0",
    "prettier-eslint": "^8.8.2",
    "react-hot-loader": "^4.8.4",
    "redux-mock-store": "^1.5.4",
    "regenerator-runtime": "^0.13.2",
    "sass-loader": "^7.0.3",
    "style-loader": "^0.23.1",
    "terser-webpack-plugin": "^1.2.3",
    "url-loader": "^1.1.2",
    "webpack": "^4.39.0",
    "webpack-cli": "^3.3.1",
    "webpack-dev-server": "^3.3.1",
    "webpack-hot-middleware": "^2.24.4",
    "webpack-merge": "^4.2.1",
    "worker-loader": "^2.0.0"
  },
  "jest": {
    "globals": {
      "NODE_ENV": "test"
    },
    "transform": {
      "\\.[jt]sx?$": "babel-jest",
      "^.+\\.svg$": "jest-svg-transformer"
    },
    "verbose": false,
    "rootDir": ".",
    "collectCoverageFrom": [
      "**/*.{js,jsx,ts,tsx}",
      "!**/*.d.ts"
    ],
    "moduleFileExtensions": [
      "js",
      "jsx",
      "ts",
      "tsx"
    ],
    "moduleNameMapper": {
      "\\.(css|less|scss|sass)$": "identity-obj-proxy",
      "^components/(.*)$": "<rootDir>/src/components/$1",
      "^utils/(.*)$": "<rootDir>/src/utils/$1",
      "^locales(.*)$": "<rootDir>/src/locales/$1",
      "^assets(.*)$": "<rootDir>/src/assets/$1",
      "^styles/(.*)$": "<rootDir>/src/styles/$1"
    },
    "modulePathIgnorePatterns": [
      "./dist"
    ],
    "coverageDirectory": "<rootDir>/tests/coverage/"
  }
}

我的 package.json 位于项目的根目录。

我尝试过的

我尝试了下面的建议,但现在我得到了

npm install -registry [[[[https://myregistryurl]]]]
========================== Starting Command Output ===========================
##[debug]which 'bash'
##[debug]found: '/bin/bash'
##[debug]which '/bin/bash'
##[debug]found: '/bin/bash'
##[debug]/bin/bash arg: --noprofile
##[debug]/bin/bash arg: --norc
##[debug]/bin/bash arg: /home/vsts/work/_temp/7aa1a129-08a3-43cb-8973-ce9f3c9748c4.sh
##[debug]exec tool: /bin/bash
##[debug]arguments:
##[debug]   --noprofile
##[debug]   --norc
##[debug]   /home/vsts/work/_temp/7aa1a129-08a3-43cb-8973-ce9f3c9748c4.sh
/bin/bash --noprofile --norc /home/vsts/work/_temp/7aa1a129-08a3-43cb-8973-ce9f3c9748c4.sh
npm ERR! Maximum call stack size exceeded

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/vsts/.npm/_logs/2020-12-01T09_22_16_890Z-debug.log
##[debug]Exit code 1 received from tool '/bin/bash'

这可能是因为正在创建的 vmImages 正在填满 azure 缓存或其他什么?

我尝试添加 - script: npm cache clean --f 但这没有任何作用。

更新

似乎错误与注册表有关,我在注册表中得到了一堆 401

npm http fetch GET 401 ...
npm http fetch GET 401 ...
npm http fetch GET 401 ...
npm http fetch GET 401 ...
npm http fetch GET 401 ...
...

【问题讨论】:

  • 在没有 Azure devops 的情况下在本地运行 npm 测试结果如何?

标签: azure jestjs azure-pipelines npm-install pipeline


【解决方案1】:

我 100% 确定这是正确的。但我怀疑是本地与天蓝色管道之间的路径执行文件的问题。

您可以通过在 CI 上创建脚本测试来尝试以下操作吗?

package.json

{
  "test:ci": "node_modules/.bin/jest"
}

然后你执行这个命令而不是本地命令:

- script: npm run test:ci

【讨论】:

  • 谢谢,但仍然出现错误...更新了问题:)
  • 你能收集完整的堆栈跟踪吗?
  • 此运行的完整日志可在以下位置找到:/home/vsts/.npm/_logs/2020-12-01T09_22_16_890Z-debug.log。这个主目录在哪里?我尝试从管道运行中下载日志,但事实并非如此。
  • 你不需要看完整的。只是上面消息所在的堆栈
  • 现在更新了,注意我把注册表链接去掉了。