首页 > 解决方案 > 安装 fs-extra 时失败 - react-native

问题描述

〜我正在为android创建一个新应用程序,当我命令react-native run-android时出现此错误:错误:捆绑失败:错误:无法解析模块fs来自C:\Users\luis.arnoni.fritzen\Documents\ReactNative\Hello\node_modules\expo-cli\build\exp.jsfsHaste模块映射中不存在模块

阅读一些文档,这似乎是 fs 包的问题。我尝试安装 fs-extra 包,但出现错误

   npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.9 
   (node_modules\fsevents):
   npm WARN optional SKIPPING OPTIONAL DEPENDENCY: Error: EPERM: operation 
   not permitted, rename 
   'C:\Users\luis.arnoni.fritzen\Documents\ReactNative
   \Hello\node_modules\.staging\fsevents-aa6bf958\node_modules\rc' -> 
   'C:\Users\luis.arnoni.fritzen\Documents
   \ReactNative\Hello\node_modules\.staging\rc-e2a21b3f'

   npm ERR! path C:\Users\luis.arnoni.fritzen\Documents\ReactNative\
   Hello\node_modules\fs-extra\lib\fs
   npm ERR! code EPERM
   npm ERR! errno -4048
   npm ERR! syscall unlink
   npm ERR! Error: EPERM: operation not permitted, unlink 
   'C:\Users\luis.arnoni.fritzen\Documents\
   ReactNative\Hello\node_modules\fs-extra\lib\fs'
   npm ERR!  { [Error: EPERM: operation not permitted, unlink 
   'C:\Users\luis.arnoni.fritzen\Documents\ReactNative\
   Hello\node_modules\fs-extra\lib\fs']
   npm ERR!   cause:
   npm ERR!    { Error: EPERM: operation not permitted, unlink 
   'C:\Users\luis.arnoni.fritzen\Documents\ReactNative\
   Hello\node_modules\fs-extra\lib\fs'
   npm ERR!      errno: -4048,
   npm ERR!      code: 'EPERM',
   npm ERR!      syscall: 'unlink',
   npm ERR!      path:
   npm ERR!       
   'C:\\Users\\luis.arnoni.fritzen\\Documents\\ReactNative\\
   Hello\\node_modules\\fs-extra\\lib\\fs' },
   npm ERR!   stack:
   npm ERR!    'Error: EPERM: operation not permitted, unlink 
   \'C:\\Users\\luis.arnoni.fritzen\\Documents\\
   ReactNative\\Hello\\node_modules\\fs-extra\\lib\\fs\'',
   npm ERR!   errno: -4048,
   npm ERR!   code: 'EPERM',
   npm ERR!   syscall: 'unlink',
   npm ERR!   path:
   npm ERR!    'C:\\Users\\luis.arnoni.fritzen\\Documents\\
   ReactNative\\Hello\\node_modules\\fs-extra\\lib\\fs',
   npm ERR!   parent: 'Hello' }
   npm ERR!
   npm ERR! The operation was rejected by your operating system.
   npm ERR! It's possible that the file was already in use (by a text 
   editor or antivirus),
   npm ERR! or that you lack permissions to access it.
   npm ERR!
   npm ERR! If you believe this might be a permissions issue, please 
   double-check the
   npm ERR! permissions of the file and its containing directories, or try 
   running
   npm ERR! the command again as root/Administrator (though this is not 
   recommended).

   npm ERR! A complete log of this run can be found in:
   npm ERR!     C:\Users\luis.arnoni.fritzen\AppData\Roaming\npm- 
   cache\_logs\2019-09-16T16_08_43_971Z-debug.log

标签: react-nativefs-extra

解决方案


react-native没有完整的节点环境。并非所有节点模块都可以与 react-native 一起使用。您可以考虑使用https://github.com/itinance/react-native-fs


推荐阅读