【问题标题】:Unable to resolve module "./path_to_file"无法解析模块“./path_to_file”
【发布时间】:2021-11-07 14:56:53
【问题描述】:

我是 React Native 的新手,我正在尝试制作一个小应用程序。我遵循了有关如何启动 CRNA 项目以及如何在手机上对其进行测试的教程。 它起作用了,但是一旦我创建了我的第一个组件,我就收到了这个错误:

Building JavaScript bundle: error

Unable to resolve module ./Components/Search from C:\Users\fredd\OneDrive\Bureau\ReactNative\MoviesAndMe\App.js: 

None of these files exist:
  * Components\Search(.native|.android.ts|.native.ts|.ts|.android.tsx|.native.tsx|.tsx|.android.js|.native.js|.js|.android.jsx|.native.jsx|.jsx|.android.json|.native.json|.json)
  * Components\Search\index(.native|.android.ts|.native.ts|.ts|.android.tsx|.native.tsx|.tsx|.android.js|.native.js|.js|.android.jsx|.native.jsx|.jsx|.android.json|.native.json|.json)
  1 | import React from 'react';
> 2 | import Search from './Components/Search';
    |                     ^
  3 |
  4 | export default class App extends React.Component {
  5 |   render() {

我是一个完整的初学者,所以也许我错过了一些东西,但我确信我做了和教程一样的事情。

这是我的文件:

App.js

import React from 'react';
import Search from './Components/Search';

export default class App extends React.Component {
  render() {
    return (
      <Search/>
    );
  }
}

search.js(组件)

import React from "react";
import {View, Button, TextInput} from 'react-native';

class Search extends React.Component {
    render() {
        return (
            <View>
                <TextInput placeholder="Titre du film"/>
                <Button title="Rechercher" onPress={() => {}}/>
            </View>
        )
    }
}

export default Search;

你能帮帮我吗?

【问题讨论】:

  • 可以分享文件夹/文件结构吗?

标签: javascript android reactjs react-native components


【解决方案1】:

由于你的 search.js 是小写的,你需要像这样导入它import Search from './Components/search';

【讨论】:

    猜你喜欢
    • 2017-12-11
    • 2018-11-10
    • 2020-04-15
    • 2021-07-14
    • 2020-12-02
    • 2021-07-21
    • 2018-03-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多