Error: node_modules\react-native-fs\FS.common.js: Unexpected token, expected "," (30:29) when build React project

Viewed 456

I have just installed jsmediatags in my project. Then when I try to build my project, it has the error as below

...
Creating an optimized production build...
Failed to compile.

.\node_modules\jsmediatags\build2\ReactNativeFileReader.js
Cannot find module: 'react-native-fs'. Make sure this package is installed.

You can install this package by running: npm install react-native-fs.

Then I keep installing react-native-fs, and it still has the error.

...
Creating an optimized production build...
Failed to compile.

./node_modules/react-native-fs/FS.common.js
SyntaxError: D:\workspace\zmp3-desktop\node_modules\react-native-fs\FS.common.js: Unexpected token, expected "," (30:29)

  28 | };
  29 |
> 30 | var normalizeFilePath = (path: string) => (path.startsWith('file://') ? path.slice(7) : path);
     |                              ^
  31 |
  32 | type MkdirOptions = {
  33 |   NSURLIsExcludedFromBackupKey?: boolean; // iOS only
...

At that time, I can't find out any article to fix this problem.

1 Answers

And after a lot of time to find a way to fix this, I try to comment var RNFS = require('react-native-fs'); and the code related in node_modules\jsmediatags\build2\ReactNativeFileReader.js then uninstall react-native-fs, and it works.

I know this isn't the best way to fix this problem, but maybe you can try it.

Related