javascript - 找不到模块 'newman' 需要堆栈 :

标签 javascript node.js postman newman

我在我的计算机上全局安装了“newman”包并且能够在命令行上运行 newman

npm install -g newman 

但是,我需要在 nodejs 脚本中运行我的测试集合,下面的语句会抛出异常

找不到模块“newman”需要堆栈:

const newman = require('newman'); 

有解决这个问题的想法吗?

奥斯汀

// this is full error stack
internal/modules/cjs/loader.js:797
    throw err;
    ^

Error: Cannot find module 'newman'
Require stack:
- C:\xxx\postman-tests\parallel.js
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:794:15)
    at Function.Module._load (internal/modules/cjs/loader.js:687:27)
    at Module.require (internal/modules/cjs/loader.js:849:19)
    at require (internal/modules/cjs/helpers.js:74:18)
    at Object.<anonymous> (C:\xxx\postman-tests\parallel.js:8:16)
    at Module._compile (internal/modules/cjs/loader.js:956:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:973:10)
    at Module.load (internal/modules/cjs/loader.js:812:32)
    at Function.Module._load (internal/modules/cjs/loader.js:724:14)
    at Function.Module.runMain (internal/modules/cjs/loader.js:1025:10) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    'C:\\xxx\\postman-tests\\parallel.js'
  ]
}

最佳答案

你已经全局安装了 newman 包。为了在你的项目中使用它,你需要在你的项目中本地安装它。如果您的项目没有 package.json 文件,您可以通过在项目的根目录中运行 npm init 来初始化它。之后,您可以通过 npm install newman 安装软件包,将其添加到您的依赖项中。现在您的项目中可能需要该包。

关于javascript - 找不到模块 'newman' 需要堆栈 :,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58665717/

相关文章:

javascript - 如何防止递归函数重新初始化累加变量?

node.js - 带 Node.JS 和 Express 以及 .ejs 的 SPA

Javascript es2015导入语法

javascript - postman :在环境变量的声明中使用请求名称

javascript - 从$scope获取数据

javascript - 单击按钮时如何使 Canvas 文本消失

javascript - 为什么下面的 jQuery 选择器不返回两个元素?

javascript - 双向流转换器的设计模式

node.js - Sequelize : Issue in bulkCreate while inserting an array

postman - 限制 Postman 上的某些 HTTP 方法