简体   繁体   English

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

[英]Cannot find module 'newman' Require stack:

I installed "newman" package on my computer globally and able to run newman on the command line我在我的计算机上全局安装了“newman”package,并且能够在命令行上运行 newman

npm install -g newman 

However, I need to run my test collections in nodejs script and the following statement throws an exception但是,我需要在 nodejs 脚本中运行我的测试 collections 并且以下语句引发异常

Cannot find module 'newman' Require stack:找不到模块“newman”需要堆栈:

const newman = require('newman'); 

Any ideas to fix this problem?有什么想法可以解决这个问题吗?

Austin奥斯汀

// 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'
  ]
}

you have installed newman package globally.您已经在全球范围内安装了newman package。 In order to use it in your project you need to install it locally in your project.为了在您的项目中使用它,您需要在项目中本地安装它。 If your project does not have a package.json file you can init it by running npm init in the root directory of your project.如果您的项目没有package.json文件,您可以通过在项目的根目录中运行npm init来初始化它。 After that you can install the package by npm install newman to add it to your dependencies.之后,您可以通过npm install newman安装 package 以将其添加到您的依赖项中。 Now the package can be required within your project.现在,您的项目中可能需要 package。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM