React Native "requires" gotcha? Works for a local image file but not a csv file in the same directory

a React Native is new here.

Inside my component (inside the App.js file) I declare a variable and set it to a local CSV file using require( ).

These errors --->

componentWillMount() {
  var csvFilePath = require('./assets/imagesdata.csv');

However, when I install this in CSV, I want this to give me an error:

Unable to resolve ./assets/imagesdata.csv" from ".//App.js`: The module `./assets/imagesdata.csv` could not be found"

The curious thing is that if I just exit the CSV file for another file in the same directory, let it use the .png image file, it works fine without errors - what gives?

There is no error (the subject in the .png file in the SAME subdirectory as a .csv file that did not work) --->

componentWillMount() {
  var csvFilePath = require('./assets/locationlogo.png');

Is there any specific CSV import syntax that I am not familiar with React?

, , CSV, (imagesdata.csv), assets/, .png, (locationlogo.png ).

enter image description here

!

FYI: googled (, , : https://github.com/oblador/react-native-vector-icons/issues/626

rm ./node_modules/react-native/local-cli/core/__fixtures__/files/package.json , ).

0
1

, , .

React Native , JSON , CSV. CSV, FS (Android/iOS), .

- react-native-fs. CSV :

var RNFS = require('react-native-fs');

RNFS.readFile("imagesdata.csv")
  .then((result) => {
    console.log('file contents', result);
  })
  .catch((err) => {
    console.log(err.message, err.code);
  });

, , , . , --fs.

0

Source: https://habr.com/ru/post/1687877/


All Articles