【问题标题】:How do I run a simple file script from using yarn in windows如何在 windows 中使用 yarn 运行一个简单的文件脚本
【发布时间】:2018-09-06 09:10:20
【问题描述】:

我是整个 Node.js 世界的新手,但这个可能很简单的问题让我发疯了。这基本上是我在一个更大的项目中遇到的问题的简化版本。

文件结构

package.json
test1

我的 package.json 看起来像这样:

{
  "name": "Temp",
  "version": "1.0.0",
  "main": "index.js",
  "license": "MIT",
  "scripts": {
    "testscript": "test1",
    "testrun":"yarn testscript"
  }
}

test1 只包含一个简单的console.log('test') 命令。

现在当我执行yarn testrun 时,出现以下错误:

PS C:\dev\temp> yarn testrun
yarn run v1.9.4
$ yarn testscript
$ test1
'test1' is not recognized as an internal or external command,
operable program or batch file.
error Command failed with exit code 1.

如果文件有扩展名(即 test1.js),那么它会识别并工作。

在任何人说添加文件扩展名之前,这只是我创建的最简单的用例。有一个更大的项目包含这种东西,而且似乎对我所有的 Linux 和 Mac 朋友来说都可以工作。

【问题讨论】:

  • 类型:node test1 如:"testscript": "node test1",

标签: node.js windows yarnpkg


【解决方案1】:

你想要node test1。您现在拥有的是尝试运行一个名为“test1”的不存在的程序。您希望 existent 程序节点使用参数“test1”运行,这将告诉节点运行名为“test1.js”(或任何扩展名)的 JavaScript 文件。

考虑文档:yarn scripts

所以:

{
  "name": "Temp",
  "version": "1.0.0",
  "main": "index.js",
  "license": "MIT",
  "scripts": {
    "testscript": "node test1",
    "testrun":"yarn testscript"
  }
}

【讨论】:

  • 是的,这行得通。确实很明显。我对它在 Linux 上运行良好的事实感到困惑。真的没有考虑过在它前面加上“node ...”命令。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-06-10
  • 2020-08-30
  • 2023-03-22
  • 1970-01-01
  • 2021-02-15
相关资源
最近更新 更多