Browserify bundle.js错误:exec不是函数

时间:2018-01-18 15:38:04

标签: javascript node.js npm browserify samba

我最近安装了Node.js,npm,samba-client和browserify。问题是,我在我的bundle.js文件中得到一个未捕获的TypeError,我无法解决这个问题。

bundle.js:107 
    Uncaught TypeError: exec is not a function
    at SambaClient.execute (bundle.js:107)
    at SambaClient.mkdir (bundle.js:58)
    at Object.8.samba-client (bundle.js:1319)
    at s (bundle.js:1)
    at e (bundle.js:1)
    at bundle.js:1

我做了一些研究,发现可能是package.json文件有点不对。

{
  "name": "package.json",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "directories": {
    "lib": "lib"
  },
  "dependencies": {
    "child_process": "^1.0.2",
    "debug": "^3.1.0",
    "open": "0.0.5",
    "path": "^0.12.7",
    "samba-client": "^2.0.0",
    "util": "^0.10.3"
  },
  "devDependencies": {},
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC"
}

但如果我诚实,我不知道该怎么做。

这是part.,它首先在bundle.js中失败:

SambaClient.prototype.execute = function(cmd, cmdArgs, workingDir, cb) {
  var fullCmd = wrap(util.format('%s %s', cmd, cmdArgs));

  var command = ['smbclient', this.getSmbClientArgs(fullCmd).join(' ')].join(' ');

  var options = {
    cwd : workingDir
  };

  **exec(command, options, function(err, stdout, stderr) {**
    var allOutput = (stdout + stderr);
    if(err !== null) {
      err.message += allOutput;
    }
    cb(err, allOutput);
  });
};

希望有人可以帮助我。 :)

1 个答案:

答案 0 :(得分:0)

您正确导入了exec函数吗?

const exec  = require('child_process').exec;