【发布时间】:2020-02-21 02:26:26
【问题描述】:
Node.js、Webpack
在这个项目中使用了webpack,这里安装了FS。 此代码需要读取文件,但返回错误“Uncaught TypeError: fs.readFile is not a function”
const bookForm = document.querySelector(".book-form");
const select = document.querySelector(".select"); const fs = require("fs");
export function abc() { bookForm.addEventListener("submit", e => {
console.log(select.options[select.selectedIndex].text);
e.preventDefault();
fs.readFile("file.txt", function(error, data) {
console.log("file read");
if (error) throw error;
console.log(data); });
}); }
【问题讨论】:
-
是 Node.js 还是浏览器?
-
是的,webpack里有收集到的前端项目(语法错误见谅)