【发布时间】:2022-02-19 22:36:17
【问题描述】:
首先我从link 下载了 node js。
然后我安装了 browserify npm install -g browserify
然后我安装了fs npm install fs
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<script>
const fs = require('fs');
fs.writeFile("/tmp/test", "Hey there!", function(err) {
if(err) {return console.log(err);}
console.log("The file was saved!");
});
</script>
</body>
</html>
我收到以下错误:
Uncaught ReferenceError: require is not defined
at index.html:12:12
为什么 require 仍然没有定义?我该怎么做才能使代码可执行?
【问题讨论】:
-
不仅在浏览器环境中没有定义 require,Node 的库(包括 fs)也没有。
标签: javascript node.js