【发布时间】:2018-11-12 15:55:09
【问题描述】:
当我尝试使用新的 Node.js 对 ES6 模块的支持时(例如使用 node --experimental-modules script.mjs),为什么会出现这样的错误?
// script.mjs
import * as fs from 'fs';
// TypeError: fs.readFile is not a function
fs.readFile('data.csv', 'utf8', (err, data) => {
if (!err) {
console.log(data);
}
});
// TypeError: fs.readdirSync is not a function
fs.readdirSync('.').forEach(fileName => {
console.log(fileName);
});
【问题讨论】:
标签: node.js fs es6-modules