【问题标题】:npm - Issue to force npm run jasmine from local node_modulesnpm - 强制 npm 从本地 node_modules 运行 jasmine 的问题
【发布时间】:2017-04-06 20:31:05
【问题描述】:

我将 jasmine npm 模块安装为全局。后来,为了共享代码并让团队轻松拥有所有依赖项,我使用 --save-dev 在项目本地安装了 jasmine。

问题是它试图从 node_modules 全局一个而不是本地一个执行。

Package.json

{
  "name": "tdd",
  "version": "1.0.0",
  "description": "testing tdd practices",
  "main": "index.js",
  "scripts": {
    "test": "$(npm bin)/jasmine"
  },
  "keywords": [
    "test",
    "tdd",
    "jasmine",
    "node"
  ],
  "license": "ISC",
  "devDependencies": {
    "jasmine": "^2.4.1"
  }
}

如果我的测试通过了,我不会出错。如果测试未通过,我会收到指向全局 node_modules 的错误。

Albertos-MBP:TDD albertof$ npm run test

> tdd@1.0.0 test /Users/albertof/Projects/Web/TDD
> jasmine

Started
......FF

Failures:
1) Html Replacement Regex: should replace . in src attributes for <img src="./hello.jpg"> 
  Message:
    Expected '<img static/hello.jpg">' to be '<img src="static/hello.jpg">'.
  Stack:
    Error: Expected '<img static/hello.jpg">' to be '<img src="static/hello.jpg">'.
        at Object.<anonymous> (/Users/albertof/Projects/Web/TDD/spec/htmlSpec.js:22:62)

8 specs, 1 failures
Finished in 0.015 seconds

npm ERR! Darwin 15.5.0
npm ERR! argv "/usr/local/bin/node" "/Users/albertof/npm-global/bin/npm" "run" "test"
npm ERR! node v6.0.0
npm ERR! npm  v3.8.8
npm ERR! code ELIFECYCLE
npm ERR! tdd@1.0.0 test: `jasmine`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the tdd@1.0.0 test script 'jasmine'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the tdd package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     jasmine
npm ERR! You can get information on how to open an issue for this project with:
npm ERR!     npm bugs tdd
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!     npm owner ls tdd
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR!     /Users/albertof/Projects/Web/TDD/npm-debug.log

尝试从安装的全局 node_modules 执行的原因是什么? 运行npm bin返回当前项目的本地/Users/albertof/Projects/Web/TDD/node_modules/.bin

【问题讨论】:

    标签: node.js npm


    【解决方案1】:

    编辑你的 package.json

    "scripts": {
        "test": "$(npm bin)/jasmine; exit 0"
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-08-25
      • 2011-11-16
      • 2021-04-06
      • 1970-01-01
      • 2019-11-30
      • 2015-05-28
      • 2020-11-26
      相关资源
      最近更新 更多