简体   繁体   English

Node.js writeFile [未捕获的类型错误:无法读取未定义的属性“writeFile”]

[英]Node.js writeFile [Uncaught TypeError: Cannot read property 'writeFile' of undefined]

I can't get writeFile to write file.我无法让 writeFile 写入文件。 It works find if it's not in a function so it's not the module but when the function is called, it results in an error.它可以找到它是否不在函数中,因此它不是模块,但是当调用该函数时,它会导致错误。

[Uncaught TypeError: Cannot read property 'writeFile' of undefined] [未捕获的类型错误:无法读取未定义的属性 'writeFile']

JS Code: JS代码:

var fs = require('fs');
var input = document.getElementById('filename');
var fileName = input.value;

function recordToFilename() {
var input = document.getElementById('filename');
var fileName = input.value;
var qw = fileName;

if (qw) {
    alert('value of: ' + qw);
    console.log(qw);
    // demo output
    var myObject = {
        qw: qw,
        fullN: function() {
            return this.qw;
        }
    };

    document.getElementById("demo").innerHTML = myObject.fullN();
    var path = "danny.txt";
    var data1 = "jdsfhadj"
    fs.writeFile(path,data1)
    //end demo output code
    } else {
        alert('Please enter a filename!');
        input.focus();
    }
};

HTML Code: HTML代码:

<html>
<head>
    <title>writeFile</title>
    <script src="jquery.js"></script>
    <script src="bonescript.js"></script>
    <script src="test_3.js"></script>
</head>
<body>

    <label for="filename">Filename</label>
    <input name="filename" id="filename" type="text">

    <a id="enter_button" onclick="recordToFilename();"    href="javascript:void(0);" title="enter">enter name</a>
    <br>
    <p id="demo"></p>
</body>
</html>

请升级您的节点版本以解决此问题。

暂无
暂无

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

相关问题 未捕获的类型错误:无法读取 node.js 上未定义的属性“长度” - Uncaught TypeError: Cannot read property 'length' of undefined on node.js 未捕获的类型错误:无法读取 node.js 中未定义的属性“通道” - Uncaught TypeError: Cannot read property 'channel' of undefined in node.js 'Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'writeFile')' 尝试使用 REACT 写入文件时出错 - 'Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'writeFile')' error while trying to write to a file with REACT 未捕获的TypeError:无法读取null Node.js的属性&#39;getContext&#39; - Uncaught TypeError: Cannot read property 'getContext' of null Node.js Node.js 抛出 TypeError:无法读取未定义的属性“testModule” - Node.js throwing TypeError: Cannot read property 'testModule' of undefined TypeError:无法读取未定义的属性“ get”(Node.js) - TypeError: Cannot read property 'get' of undefined (Node.js) TypeError:无法读取node.js中未定义的属性“名称” - TypeError: Cannot read property 'name' of undefined in node.js Node.js UnhandledPromiseRejection:TypeError:无法读取未定义的属性“ sign” - Node.js UnhandledPromiseRejection: TypeError: Cannot read property 'sign' of undefined TypeError:无法读取Node.js中未定义的属性“ length” - TypeError: Cannot read property 'length' of undefined in Node.js Node.js -&gt; TypeError:无法读取上下文中未定义的属性“then” - Node.js -> TypeError: Cannot read property 'then' of undefined at Context
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM