You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

React Native中ParallaxScrollView模块报错求助:类型声明缺失及安装失败

Fixing Issues with react-native-parallax-scrollview in Your React Native Project

Let’s work through both of your problems step by step to get your parallax scroll view up and running:

1. Resolving the "Could not find a declaration file" Error

The TypeScript error occurs because react-native-parallax-scrollview doesn’t have official type definitions (which is why npm install @types/react-native-parallax-scrollview fails—those types don’t exist in the npm registry). You have two straightforward fixes:

Option 1: Create a Custom Declaration File

  • In your project root, make a new folder called typings (if it doesn’t already exist).
  • Inside typings, create a file named react-native-parallax-scrollview.d.ts with this content:
    declare module 'react-native-parallax-scrollview';
    
  • Update your tsconfig.json to include this folder in type checking. Add "./typings/**/*" to the include array:
    {
      "include": [
        "src/**/*",
        "./typings/**/*"
      ]
    }
    

Option 2: Skip Type Checking for This Module

If you don’t want to set up custom typings, add a // @ts-ignore comment above your import to bypass TypeScript’s type check for this module:

// @ts-ignore
import ParallaxScrollView from 'react-native-parallax-scrollview';

2. Fixing the Initial "expected string or class/function" Error

Looking at your code, the root cause here is incorrect formatting for the backgroundSource and userImage props. The react-native-parallax-scrollview expects these to match React Native’s Image component source format—network images need to be passed as an object with a uri key, not a raw string.

Update those props in your component:

<ParallaxScrollView
  windowHeight={SCREEN_HEIGHT * 0.4}
  backgroundSource={{ uri: 'http://i.imgur.com/UyjQBkJ.png' }} // Fixed format
  navBarTitle='John Oliver'
  userName='John Oliver'
  userTitle='Comedian'
  userImage={{ uri: 'http://i.imgur.com/RQ1iLOs.jpg' }} // Fixed format
  leftIcon={{name: 'rocket', color: 'rgba(131, 175, 41, 1)', size: 30, type: 'font-awesome'}}
  rightIcon={{name: 'user', color: 'rgba(193, 193, 193, 1)', size: 30, type: 'font-awesome'}}
/>

After making these changes, your parallax scroll view should render without those initial errors.


内容的提问来源于stack exchange,提问作者Deepthi Sareddy

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.06 13:57:37