gpt4 book ai didi

javascript - Fs 模块错误

转载 作者:行者123 更新时间:2023-12-03 05:48:44 25 4
gpt4 key购买 nike

我正在使用 Node v6.7.0 尝试使用“fs”模块,但出现错误,如下所示。我尝试另外安装它,但不起作用(即使我添加整个路径)。如果我检查网站 https://www.npmjs.com/package/fs你可以看到该消息。有什么想法如何使用该模块吗?

var filename = process.argv[2];
var version = process.argv[3];
var fs = require('fs');
var prompt = require('C:/Program Files/nodejs/node_modules/prompt');
var p4 = require('C:/Program Files/nodejs/node_modules/p4');



p4.edit(filename, function(err, data) {
if (err) {
console.error(err.message);
}
fs.readFile(filename, 'utf8', function (err, data) {
if (err) {
return console.log(err);
}
var result = data.replace(/string to be replaced/g, version);

fs.writeFile(filename, result, 'utf8', function (err) {
if (err) return console.log(err);
});
});
console.log(data);

prompt.start();
prompt.get('p4 submit -c changelist', function (err, result) {
if(err) {
console.log(err.message);
}
console.log(result);
});
});

fs.js:303
binding.open(pathModule._makeLong(path),
^

TypeError: path must be a string or Buffer
at TypeError (native)
at Object.fs.readFile (fs.js:303:11)
at C:\WorkSpace\http.js:22:9
at C:\Program Files\nodejs\node_modules\p4\p4.js:13:24
at ChildProcess.exithandler (child_process.js:213:5)
at emitTwo (events.js:106:13)
at ChildProcess.emit (events.js:191:7)
at maybeClose (internal/child_process.js:877:16)
at Socket.<anonymous> (internal/child_process.js:334:11)
at emitOne (events.js:96:13)

Process finished with exit code 1

最佳答案

fs 是一个 Nodejs 核心模块:这里是 the fs documentation

关于javascript - Fs 模块错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40234178/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com