Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Reactjs React Native-使用我创建的自定义组件时出错(错误:未定义无法解析模块<;MyModule>;)_Reactjs_React Native_Npm_Publish_Package.json - Fatal编程技术网

Reactjs React Native-使用我创建的自定义组件时出错(错误:未定义无法解析模块<;MyModule>;)

Reactjs React Native-使用我创建的自定义组件时出错(错误:未定义无法解析模块<;MyModule>;),reactjs,react-native,npm,publish,package.json,Reactjs,React Native,Npm,Publish,Package.json,我制作了一个名为“react native weekly calendar”的自定义组件, 我正试图将其发布到开源社区, 但我想先测试一下。当我试图通过npm安装--save../测试它时,它抛出一个错误 我的目录结构: - react-native-weekly-calendar (folder) - index.js - package.json - src (folder) - Locale.js - Style.js index.

我制作了一个名为“react native weekly calendar”的自定义组件, 我正试图将其发布到开源社区, 但我想先测试一下。当我试图通过
npm安装--save../
测试它时,它抛出一个错误

我的目录结构:

- react-native-weekly-calendar (folder)
    - index.js
    - package.json
    - src (folder)
        - Locale.js
        - Style.js
index.js:

import React, { useState, useEffect, useRef } from 'react';
import { Text, View, ScrollView, TouchableOpacity, TouchableWithoutFeedback, Modal, Platform, ActivityIndicator } from 'react-native';
import PropTypes from 'prop-types';
import moment from 'moment/min/moment-with-locales';
import DateTimePicker from '@react-native-community/datetimepicker';
import { FontAwesome } from 'react-native-vector-icons';
import { applyLocale, displayTitleByLocale } from './src/Locale';
import styles from './src/Style';

const WeeklyCalendar = props => {
    ...
}

export default WeeklyCalendar;
package.json:

{
  "name": "react-native-weekly-calendar",
  "version": "0.1.0",
  "description": "Weekly Calendar component for React Native",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "repository": {
    "type": "git",
    "url": "git+https://github.com/codeinjuice/react-native-weekly-calendar.git"
  },
  "keywords": [
    "react",
    "reactnative",
    "react-native",
    "react-native-component",
    "calendar",
    "weeklycalendar",
    "weekly-calendar",
    "scheduler",
    "datepicker",
    "date-picker"
  ],
  "author": "codeinjuice",
  "license": "MIT",
  "bugs": {
    "url": "https://github.com/codeinjuice/react-native-weekly-calendar/issues"
  },
  "homepage": "https://github.com/codeinjuice/react-native-weekly-calendar#readme",
  "dependencies": {
    "moment": "^2.24.0",
    "prop-types": "^15.5.7",
    "@react-native-community/datetimepicker": "~2.1.0",
    "react-native-vector-icons": "~6.6.0"
  },
  "devDependencies": {
    "@babel/core": "^7.0.0",
    "metro-react-native-babel-preset": "^0.58.0",
    "react": "~16.9.0",
    "react-native": "0.61.4"
  }
}
下面是我如何使用上述文件进行测试的:

$ npx react-native init sample
$ cd sample
$ npm install --save ../react-native-weekly-calendar
$ vim App.js
然后我添加了
import WeeklyCalendar from'react native WeeklyCalendar'在App.js中。
最后我跑了

$ npx react-native run-ios
在模拟器中,我得到以下错误:

无法从“App.js”解析模块“react native weekly calendar”:在项目中找不到react native weekly calendar

我是否在
package.json
中设置了依赖项设置错误

我不明白为什么它总是说组件在node_modules文件夹中找不到


欢迎任何建议

编辑:我将react native从0.60.*升级到了0.61.4,它也可以与npm一起工作。

原始答案 我使用了
$warn add../react native周历


而不是
$npm install--save../react native weekly calendar
,它可以正常工作。

一旦您的依赖项正确安装,它们应该出现在
包.json中的属性
依赖项
devdependency
下file@keikai你是说tester项目中的
package.json
?它的
依赖项
包含“react”:“16.9.0”、“react native”:“0.61.5”、“react native weekly calendar”:“文件:../react native weekly calendar”