我制作了一个名为“react原生-每周日历”的自定义组件,我试图将它发布到开源社区,但我想先测试它。当我尝试用npm install --save ../<component_name>测试它时,它会抛出一个错误。
我的目录结构:
- react-native-weekly-calendar (folder)
- index.js
- package.json
- src (folder)
- Locale.js
- Style.jsindex.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-weekly-calendar';中添加了App.js。最后我跑了
$ npx react-native run-ios在模拟器中,我得到了以下错误:
无法从‘App.js’中解析模块‘react本机-周-日历’:无法在项目中找到react本机-周日历。
我在package.json中设置了依赖项设置错误吗?
我不明白为什么当组件清楚地位于node_modules文件夹中时,它总是说组件没有找到。
欢迎任何建议!
发布于 2020-03-23 06:53:11
编辑:我升级了react-从0.60.*升级到0.61.4,它也与npm一起工作.
原始答案我使用了$ yarn add ../react-native-weekly-calendar
而不是$ npm install --save ../react-native-weekly-calendar,它起了作用。
https://stackoverflow.com/questions/60752371
复制相似问题