简体   繁体   English

尝试导入错误:当编译react-native到react-native-web时,不会从'./apiFetcher'导出'ApiGet'

[英]Attempted import error: 'ApiGet' is not exported from './apiFetcher' when compile react-native to react-native-web

I am building react native app and it run successfully on both Android and iOS. 我正在构建反应原生应用程序,它在Android和iOS上都能成功运行。 I want to convert react-native app to web app. 我想将react-native应用程序转换为web应用程序。 I try followed tutorial: https://medium.com/@jonnykalambay/your-first-hybrid-app-in-15-minutes-react-native-on-the-web-2cc2646051e as well as some source ( https://react-native-training.github.io/react-native-elements/blog/2018/12/13/react-native-web.html ). 我尝试按照教程: https//medium.com/@jonnykalambay/your-first-hybrid-app-in-15-minutes-react-native-on-the-web-2cc2646051e以及一些来源( https:/ /react-native-training.github.io/react-native-elements/blog/2018/12/13/react-native-web.html )。 But when I run on web, there is error: Attempted import error: 'ApiGet' is not exported from './apiFetcher'. 但是当我在网上运行时,出现错误:尝试导入错误:'ApiGet'不会从'./apiFetcher'导出。

My code: 我的代码:

//apiGet.js
function ApiGet(){
//some code
}

module.exports = {ApiGet}

//another file import
import {ApiGet} from './apiGet.js';
  • I tried an example for testing with this syntax import, export. 我尝试使用此语法import,export进行测试的示例。 It run successfully. 它运行成功。 My code use both ES5 and ES6. 我的代码同时使用ES5和ES6。 When I run code in react-native, it's OK. 当我在react-native中运行代码时,没关系。 I create a demo react-native-web using ES5, it's also OK. 我使用ES5创建了一个演示react-native-web,它也没问题。
  • my package.json: 我的package.json:
{
 "name": "App",
 "version": "0.0.1",
 "private": true,
 "scripts": {
   "start": "node node_modules/react-native/local-cli/cli.js start",
   "test": "jest",
   "lint": "eslint .;exit 0",
   "start-web": "react-scripts start",
   "build-web": "react-scripts build"
 },
 "jest": {
   "preset": "react-native",
   "setupFiles": [
     "./jest/setup.js"
   ],
   "collectCoverage": true,
   "unmockedModulePathPatterns": [
     "react"
   ]
 },
 "dependencies": {
   "async": "^2.5.0",
   "babel-loader": "^8.0.5",
   "babel-plugin-module-resolver": "^3.1.1",
   "babel-preset-react-app": "^6.1.0",
   "bugsnag-react-native": "^2.2.0",
   "he": "^1.1.1",
   "metro-react-native-babel-preset": "^0.51.0",
   "moment": "^2.18.1",
   "oauth-1.0a": "^2.1.0",
   "prop-types": "^15.5.10",
   "react": "16.0.0-alpha.12",
   "react-app-polyfill": "^0.1.3",
   "react-art": "^16.8.6",
   "react-dom": "^16.8.6",
   "react-native": "^0.59.6",
   "react-native-camera": "^0.13.0",
   "react-native-datepicker": "^1.4.7",
   "react-native-device-info": "^0.11.0",
   "react-native-drawer": "^2.3.0",
   "react-native-dropdown-menu": "^2.0.0",
   "react-native-fast-image": "^1.0.0",
   "react-native-fbsdk": "^0.6.1",
   "react-native-firebase": "1.1.2",
   "react-native-image-progress": "^1.0.1",
   "react-native-keyboard-aware-scroll-view": "^0.2.7",
   "react-native-modal-dropdown": "^0.4.2",
   "react-native-navbar": "^1.5.0",
   "react-native-progress": "^3.4.0",
   "react-native-push-notification": "^2.2.1",
   "react-native-qrcode": "^0.2.7",
   "react-native-root-toast": "^1.0.3",
   "react-native-router-flux": "^3.37.0",
   "react-native-scrollable-tab-view": "^0.8.0",
   "react-native-swiper": "^1.5.12",
   "react-native-vector-icons": "^4.0.0",
   "react-native-web": "^0.11.2",
   "react-native-webview-android": "^1.1.17",
   "react-navigation": "^1.0.0-beta.11",
   "react-redux": "^5.0.3",
   "react-router-dom": "^5.0.0",
   "react-router-native": "^5.0.0",
   "react-scripts": "^3.0.0",
   "redux": "^3.7.2",
   "redux-logger": "^2.6.1",
   "redux-persist": "^4.9.1",
   "redux-thunk": "^2.1.0",
   "smartech-react-native": "^1.1.1"
 },
 "devDependencies": {
   "babel-core": "^6.23.1",
   "babel-eslint": "^10.0.1",
   "babel-jest": "^24.7.1",
   "babel-polyfill": "^6.23.0",
   "babel-preset-react-native": "^1.9.0",
   "babel-preset-stage-1": "^6.24.1",
   "eslint": "^5.16.0",
   "eslint-plugin-react": "^6.8.0",
   "jest": "^24.7.1",
   "jest-react-native": "^18.0.0",
   "react-native-mock": "^0.3.1",
   "react-test-renderer": "^15.3.2",
   "redux-mock-store": "^1.2.1"
 },
 "browserslist": {
   "production": [
     ">0.2%",
     "not dead",
     "not op_mini all"
   ],
   "development": [
     "last 1 chrome version",
     "last 1 firefox version",
     "last 1 safari version"
   ]
 }
}

Please help me. 请帮我。 Thanks for advance. 谢谢你提前。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在 react-native-web monorepo 架构中尝试导入错误 - Attempted import errors in react-native-web monorepo architecture 'ActionSheetIOS' 不是从'react-native-web/dist/index' 导出的 - 'ActionSheetIOS' is not exported from 'react-native-web/dist/index' 样式组件:使用 react-native 和 react-native-web 悬停 - styled components :hover with react-native and react-native-web 错误:找不到模块“ reative-native” /未找到模块:错误:无法解析模块“ react-native-web” - Error: Cannot find module “react-native” / Module not found: Error: Cannot resolve module 'react-native-web' react-native-web 如何配置 webpack - react-native-web how to configure webpack React-Native-Web 的视频支持 - Video suport for React-Native-Web 将React-Navigation与react-native-web一起使用会引发错误,因为它无法导入与Web相关的模块 - Using React-Navigation with react-native-web throws me error because it cannot import web related module 编译失败。/src/Content.js 尝试导入错误:“重定向”未从“react-router-dom”导出 - Failed to compile ./src/Content.js Attempted import error: 'Redirect' is not exported from 'react-router-dom' 尝试导入错误:“getMoviesList”未从“./actions”导出; 反应错误 redux - Attempted import error: 'getMoviesList' is not exported from './actions'; error in react redux 反应错误“尝试导入错误:'TodoItem'未从'./Todoitem'导出。” - error in react " Attempted import error: 'TodoItem' is not exported from './Todoitem'. "
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM