【问题标题】:VSTS npm custom build task - run npm script fails with type errorVSTS npm 自定义构建任务 - 运行 npm 脚本失败并出现类型错误
【发布时间】:2018-01-08 04:02:17
【问题描述】:

我在 package.json 中定义了一些脚本,例如,

    "config": {
    "source": "./assets/stylesheets/civica-styles.scss",
    "dist": "./dist/civica-styles.css",
    "minCss": "./dist/civica-styles.min.css"
  },
  "scripts": {
    "transpile": "cross-var node-sass $npm_package_config_source $npm_package_config_dist",
    "minify": "cross-var cleancss -o $npm_package_config_minCss $npm_package_config_dist"
  }

我可以如下在命令行运行这些

npm run transpile

我在 VSTS 中设置了一个构建,它执行以下初始任务:

  1. 获取源代码(从 repo 中获取我的代码)
  2. npm install(安装 在我的 package.json 中定义的包)

现在我想添加一个运行我在package.json 中定义的transpile 的任务,所以我添加了以下npm custom 任务

  • 显示名称 => npm transpile
  • 命令 => 自定义
  • 命令和参数 => 运行转译

但是构建失败

2017-08-01T10:01:42.5125804Z ##[section]Starting: npm custom
2017-08-01T10:01:42.5125804Z ==============================================================================
2017-08-01T10:01:42.5125804Z Task         : npm
2017-08-01T10:01:42.5125804Z Description  : Install and publish npm packages, or run an npm command. Supports npmjs.com and authenticated registries like Package Management.
2017-08-01T10:01:42.5125804Z Version      : 1.0.3
2017-08-01T10:01:42.5125804Z Author       : Microsoft Corporation
2017-08-01T10:01:42.5125804Z Help         : [More Information](https://go.microsoft.com/fwlink/?LinkID=613746)
2017-08-01T10:01:42.5125804Z ==============================================================================
2017-08-01T10:01:43.3515881Z ##[error]TypeError: Cannot read property 'trim' of null
2017-08-01T10:01:43.3565858Z ##[section]Finishing: npm custom

关于如何从 VSTS 构建任务执行 npm 运行脚本的任何想法?

【问题讨论】:

  • 您使用托管代理还是您自己的私人代理?如果使用私有代理,安装的 node.js 版本是多少?

标签: npm azure-pipelines azure-pipelines-build-task npm-run


【解决方案1】:

检查 Working folder with package.json 框的 npm 任务。是文件夹路径不是文件,可以使用$(Build.SourcesDirectory)

【讨论】:

    【解决方案2】:

    从 PowerShell 任务运行 npm 对我有用。

    1. 将类型设置为“内联”
    2. 在“脚本”框中写下您的任务,例如。 npm run test
    3. 确保“工作目录”设置为“高级”下的 package.json 文件夹

    【讨论】:

      猜你喜欢
      • 2018-04-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-06-23
      • 1970-01-01
      • 1970-01-01
      • 2023-03-26
      相关资源
      最近更新 更多