无法读取文件节点8.9.1

时间:2018-01-01 20:46:09

标签: javascript node.js

文档说我使用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.

0 个答案:

没有答案