【问题标题】:Browserify bundle.js Error: exec is not a functionBrowserify bundle.js 错误:exec 不是函数
【发布时间】:2019-01-05 10:26:01
【问题描述】:

我最近安装了 Node.js、npm、samba-client 和 browserify。问题是,我的 bundle.js 文件中出现了 Uncaught 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"
}

但老实说,我不知道该怎么做。

这是在 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);
  });
};

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

【问题讨论】:

  • 你为什么在 NodeJS 代码上使用 Browserify?或者您是否尝试通过 Web 浏览器使用 Samba 客户端?
  • 准确。我正在尝试从 Web 浏览器使用 samba-client。这可能吗?
  • 不,它不是而且可能永远不会。浏览器的安全模型不允许这样做。想象一下,一个随机网站可以访问对您的机器可见的 Samba 共享... brrr。你可以做的是运行一个本地的 NodeJS 服务器来进行 Samba 通信,并有一个基于浏览器的前端。
  • 有点合乎逻辑 - 该死。那真是大开眼界。谢谢你。 :)

标签: javascript node.js npm browserify samba


【解决方案1】:

你是否正确导入了 exec 函数?

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

【讨论】:

    猜你喜欢
    • 2016-03-07
    • 2019-12-27
    • 2014-09-19
    • 1970-01-01
    • 1970-01-01
    • 2017-08-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多