文档说我使用fs.readFileSync
。 Javascript控制台说没有定义。
https://nodejs.org/dist/latest-v8.x/docs/api/fs.html#fs_threadpool_usage
var fs = require('fs');
class MonsterData {
}
MonsterData.data = [];
let filename = "./gennedmons";
MonsterData.data = fs.readFileSync("filename", "utf8");
export default MonsterData;
TypeError: fs.readFileSync is not a function[Learn More]
如何阅读文件?
完整的console.log:
loading pref showConsoleLogs before prefs were initialised, you will not get the correct result content-script.bundle.js:333:7
"Download the React DevTools for a better development experience: https://fb dot me /react-devtools" ReactDOM.js:71:9
TypeError: fs.readFileSync is not a function[Learn More] bundle.js%20line%203082%20%3E%20eval:18:20
./src/App.js
/Users/quantum/pokemon/react/src/App.js
2:8 warning '$' is defined but never used no-unused-vars
✖ 1 problem (0 errors, 1 warning)
webpackHotDevClient.js:196:7
./src/Data/MonsterData.js
/Users/quantum/pokemon/react/src/Data/MonsterData.js
8:5 warning 'filename' is assigned a value but never used no-unused-vars
✖ 1 problem (0 errors, 1 warning)
完整npm start
日志:
Compiling...
Compiled with warnings.
Warning in ./src/App.js
/Users/quantum/pokemon/react/src/App.js
2:8 warning '$' is defined but never used no-unused-vars
✖ 1 problem (0 errors, 1 warning)
Warning in ./src/Data/MonsterData.js
/Users/quantum/pokemon/react/src/Data/MonsterData.js
8:5 warning 'filename' is assigned a value but never used no-unused-vars
✖ 1 problem (0 errors, 1 warning)
You may use special comments to disable some warnings.
Use // eslint-disable-next-line to ignore the next line.
Use /* eslint-disable */ to ignore all warnings in a file.