React Native中ParallaxScrollView模块报错求助:类型声明缺失及安装失败
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 namedreact-native-parallax-scrollview.d.tswith this content:declare module 'react-native-parallax-scrollview'; - Update your
tsconfig.jsonto include this folder in type checking. Add"./typings/**/*"to theincludearray:{ "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

