React Native无法导入ImportScripts错误

时间:2017-02-17 02:52:45

标签: reactjs react-native

我收到了ImportScripts错误,这意味着我没有正确导入或导出某些内容我猜不到。我已将其缩小到import { getPath } from '~/redux/modules/camera'行。但我不确定为什么会收到错误。我导入连接,因此我可以访问dispatch,然后导入getPath函数。我还应该做什么?谢谢!

enter image description here

import React, { PropTypes, Component } from 'react';
import {
  Dimensions,
  StyleSheet,
  Text,
  TouchableHighlight,
  View
} from 'react-native';
import Camera from 'react-native-camera'
import { connect } from 'react-redux'
import { getPath } from '~/redux/modules/camera'


class NimbusCamera extends Component {
  static propTypes = {
    navigator: PropTypes.object.isRequired,
    dispatch: PropTypes.func.isRequired,
  }
  state = {
    camera: {
      aspect: Camera.constants.Aspect.fill,
      captureTarget: Camera.constants.CaptureTarget.disk,
      type: Camera.constants.Type.front,
      orientation: Camera.constants.Orientation.auto,
      flashMode: Camera.constants.FlashMode.auto,
    }
    isRecording: false,
    timeLeft: 30,
    limitReached: false
  }
  render() {
    console.log(this.props)
    return (
      <View style={styles.container}>
        <Camera
          ref={(cam) => {
            this.camera = cam;
          }}
          style={styles.preview}
          aspect={this.state.camera.aspect}
          type={this.state.camera.type}
          captureTarget={this.state.camera.captureTarget}
          captureAudio={true}
          flashMode={this.state.camera.flashMode}
          >
          <Text style={styles.capture} onPress={this.startRecording.bind(this)}>[CAPTURE]</Text>
          <Text style={styles.capture} onPress={this.stopRecording.bind(this)}>[STOP_RECORDING]</Text>
        </Camera>
      </View>
    );
  }
  startRecording = () => {
    if (this.camera) {
      this.camera.capture({mode: Camera.constants.CaptureMode.video})
          .then((data) => console.log(data))
          .catch(err => console.error(err));
      this.setState({
        isRecording: true
      });
      let timerId = setInterval(countdown, 1000);
      function countdown() {
        if (this.state.timeLeft === 0) {
          clearTimeout(timerId);
          this.setState({isRecording: false})
        } else {
          this.setState({timeLeft: this.state.timeLeft--})
        }
      }
    }
  }

  stopRecording = () => {
    if (this.camera) {
      this.camera.stopCapture();
      this.setState({
        isRecording: false
      });
    }
  } 
}

export default connect()(NimbusCamera)

const styles = StyleSheet.create({
  container: {
    flex: 1
  },
  preview: {
    flex: 1,
    justifyContent: 'flex-end',
    alignItems: 'center',
    height: Dimensions.get('window').height,
    width: Dimensions.get('window').width
  },
  capture: {
    flex: 0,
    backgroundColor: '#fff',
    borderRadius: 5,
    color: '#000',
    padding: 10,
    margin: 40
  }
});

这是我的redux相机模块。

const GET_PATH = 'GET_PATH'
const CLEAR_PATH = 'CLEAR_PATH'

initialState = {
    videoPath: ''
}

export function getPath (path) {
    return {
        type: GET_PATH,
        path
    }
}

export function clearPath () {
    return {
        type: CLEAR_PATH
    }
}

export default function camera (state = initialState, action) {
    switch (action.type) {
        case GET_PATH : 
            return {
                ...state,
                videoPath: action.path
            }
        case CLEAR_PATH : 
            return {
                ...state,
                videoPath: ''
            }
        default : 
            return state
    }
}

2 个答案:

答案 0 :(得分:0)

打包控制台中的任何日志?通常它会打印更多细节错误信息。

答案 1 :(得分:-1)

当您在代码中输入拼写错误时,

这些弹出错误也会出现。然后无法正确导入模块。首先检查你的代码是否有拼写错误:)