如何解决尝试在根目录外以expo形式导入外部通用组件
这是通用组件
import React from "react";
// import { Text } from "react-native";
const PrintHello = () => {
return <div> Hello Im working </div>;
};
export default PrintHello;
// import _ from "lodash";
这是文件夹结构
common/components
app1/src/components
app2/src
我遇到了这个错误
/Users/mac3/Documents/GitHub/curb-food/common/utils.js 4:9
Module parse Failed: Unexpected token (4:9)
You may need an appropriate loader to handle this file type,currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
| // import { Text } from "react-native";
| const PrintHello = () => {
> return <div> Hello Im working </div>;
| };
|
我尝试了所有 babel-loader 但没有任何效果
解决方法
文件类型应该是 .jsx
来处理 React 组件而不是 .js
。此外,<div>
不是 React Native 组件,您应该使用 <Text>
。如果您将文件名更改为 utils.jsx
并将您的代码替换为以下代码,它应该可以工作。
import React from "react";
import { Text } from "react-native";
const PrintHello = () => {
return <Text> Hello Im working </Text>;
};
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。