如何修复 RN 突然找不到本地模块(无法解析模块)? [英] How do I fix RN suddenly being unable to find local modules (Unable to resolve module)?

查看:37
本文介绍了如何修复 RN 突然找不到本地模块(无法解析模块)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了一个奇怪的情况,我的 RN 应用程序突然无法加载任何场景.该应用程序运行良好数周,我没有移动任何文件.失败:

I've got a strange situation where suddenly my RN app won't load any of its scenes. The app has been running fine for weeks and I haven't moved any of the files. The failure:

error: bundling: UnableToResolveError: Unable to resolve module `./src/scenes/splash` from `/Users/jcollum/projects/starsApp/index.ios.js`: Directory /Users/jcollum/projects/starsApp/src/scenes/splash doesn't exist
at Promise.resolve.then (/Users/jcollum/projects/starsApp/node_modules/react-native/packager/src/node-haste/DependencyGraph/ResolutionRequest.js:445:15)
at process._tickCallback (internal/process/next_tick.js:109:7)

我的导入语句如下:

import React, { Component } from 'react';
import { AppRegistry, StyleSheet, Text, View } from 'react-native';
import { Router, Scene } from 'react-native-router-flux';
import Icon from 'react-native-vector-icons/FontAwesome';
import Splash from './src/scenes/splash';

场景肯定存在:

$ ll /Users/jcollum/projects/starsApp/src/scenes/splash.js 
-rw-r--r--  1 jcollum  staff   722B Apr 26 10:12 /Users/jcollum/projects/starsApp/src/scenes/splash.js

它有一个export default:

import React, { Component, PropTypes } from 'react';
import { View, Text, TouchableHighlight, Image } from 'react-native';
import styles from '../styles'
import { Actions } from 'react-native-router-flux';

export default class Splash extends Component {
  componentWillMount() {
    setTimeout(() => {
      Actions.Home()
    }, 1000);
  }

  render() {
    console.log(`rendering Splash`);
    return (
      <View ...

我尝试过的事情:

  • 重新启动打包程序
  • 重置内容和设置
  • 检查以前的提交
  • 清除临时目录:rm -fr $TMPDIR/react-*

react-native --version

react-native-cli: 2.0.1
react-native: 0.43.2

可能是什么原因造成的?为什么这会突然停止加载资源?下一步要尝试什么?

What could be causing this? Why would this suddenly stop loading resources? What's the next thing to try?

推荐答案

解决方案(不知道为什么会这样,抱歉):

Solution (don't know why this works, sorry):

  1. 停止任何正在运行的打包程序

  1. Stop any running packager

将此添加到 package.json: "clean-start": "rm -rf node_modules && yarn install && rm -rf $TMPDIR/react* && npmstart --reset-cache", (或者 npm install 如果你不使用yarn)

Add this to package.json: "clean-start": "rm -rf node_modules && yarn install && rm -rf $TMPDIR/react* && npm start --reset-cache", (or npm install if you don't use yarn)

npm run clean-start

这篇关于如何修复 RN 突然找不到本地模块(无法解析模块)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆