【发布时间】:2020-09-19 09:23:51
【问题描述】:
我很难过 - 非常简单的应用程序(我是 Node 新手):
App.js
import * as RNFS from 'react-native-fs';
var config_full;
// readFile(filepath: string, encoding?: string)
RNFS.readFile('./config.toml', 'utf-8').then(res => {
config_full = toml.parse(res);
})
.catch(err => {
console.log(err.message, err.code);
});
包.json
{
"name": "samples-dashboard",
"version": "0.1.0",
"private": false,
"type": "module",
"dependencies": {
"@testing-library/jest-dom": "^4.2.4",
"@testing-library/react": "^9.5.0",
"@testing-library/user-event": "^7.2.1",
"fs": "0.0.1-security",
"gremlin": "^3.4.6",
"match-sorter": "^4.1.0",
"namor": "^2.0.2",
"react": "^16.13.1",
"react-dom": "^16.13.1",
"react-native-fs": "^2.16.6",
"react-scripts": "3.4.1",
"react-table": "^7.1.0",
"styled-components": "^5.1.1",
"toml": "^3.0.0"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject",
"predeploy": "npm run build",
"deploy": "gh-pages -d build"
},
"eslintConfig": {
"extends": "react-app"
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
},
"devDependencies": {
"gh-pages": "^2.2.0"
}
}
我得到一个错误:
Failed to compile
./node_modules/react-native-fs/FS.common.js
SyntaxError: /node_modules/react-native-fs/FS.common.js: Unexpected token, expected ";" (32:5)
30 | var normalizeFilePath = (path) => (path.startsWith('file://') ? path.slice(7) : path);
31 |
> 32 | type MkdirOptions = {
| ^
33 | NSURLIsExcludedFromBackupKey?: boolean; // iOS only
34 | NSFileProtectionKey?: string; // IOS only
35 | };
我完全不在乎我从 .toml 文件中加载什么 - 只需要从磁盘加载一些东西。我应该使用什么?
需要明确的是,我不需要将此文件传递给浏览器,我希望服务器加载文件并将 .toml 的值提供给变量。
我检查了以下内容,但似乎都没有:
- TypeError: fs.readFileSync is not a function
- https://dev-yakuza.github.io/en/react-native/react-native-fs/#read-file
- Uncaught TypeError: fs.readFileSync is not a function
- Error: fs.readFileSync is not a function
- fs.readFileSync is not a function Meteor, React
我最大的希望是核心文档 - https://github.com/alexbeletsky/toml-js - 但似乎没有一个文件系统包在那里工作。
【问题讨论】:
标签: javascript node.js react-native