TypeError: fs.readFileSync is not a function Off Basic Install

Viewed 333

I'm stumped - pretty simple app (I'm new to 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);
});

Package.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"
  }
}

And I get an error:

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 | };

I totally don't care what I use to load from the .toml file - just need to load a few things off disk. What should I be using?

To be clear, I don't need to deliver this file to the browser, I want the server to load the file and provide the value of the .toml to the variable.


I've checked the following and none seem to work:

My best hope was the core docs - https://github.com/alexbeletsky/toml-js - but none of the file system packages seemed to work there either.

1 Answers

I now realize I'm thinking about this wrong. The entire app - including config - is being downloaded to the client and run, which would include the sensitive material in the .toml.

I'll need to figure out another way to auth with the database. This question doesn't make sense.

Related