Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

I can't use a symlinked package

未关闭
#1,029 8 条评论 1 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
48/100
Issue 类型
缺陷
描述清晰度
需要澄清
活跃度
活跃
技术栈
javascript, react-native

调研方向

使用列出的 npm、React Native 和 Lerna 命令重现设置,然后检查 packages/package1/package.js 中的包入口及其从 App.tsx 的导入。跟踪基于 Metro 的 React Native 应用如何解析通过 symlink 链接的包;当该包可以被导入且 CustomButton 能够在不出现所报告故障的情况下完成渲染时,即表示完成。

由索引模型根据 Issue 内容生成。

描述

Needs: Triage :mag:
Description

Hello everyone, after the new update of react native with version 0.72, and support for Symlink, I wanted to create a small project to test these features, but when importing a package created with lerna for a monorepo, I can't import it and use it correctly.

React Native Version

0.72.1

Output of npx react-native info

info Fetching system and libraries information...
System:
OS: Linux 5.19 Ubuntu 22.04.2 LTS 22.04.2 LTS (Jammy Jellyfish)
CPU: (12) x64 AMD Ryzen 5 5600X 6-Core Processor
Memory: 5.50 GB / 15.54 GB
Shell:
version: 5.1.16
path: /bin/bash
Binaries:
Node:
version: 18.16.1
path: ~/.nvm/versions/node/v18.16.1/bin/node
Yarn:
version: 1.22.19
path: /home/linuxbrew/.linuxbrew/bin/yarn
npm:
version: 9.5.1
path: ~/.nvm/versions/node/v18.16.1/bin/npm
Watchman:
version: 2022.06.20.00
path: /home/linuxbrew/.linuxbrew/bin/watchman
SDKs:
Android SDK: Not Found
IDEs:
Android Studio: Not Found
Languages:
Java:
version: 11.0.19
path: /usr/bin/javac
Ruby:
version: 3.0.2
path: /usr/bin/ruby
npmPackages:
"@react-native-community/cli": Not Found
react:
installed: 18.2.0
wanted: 18.2.0
react-native:
installed: 0.72.1
wanted: 0.72.1
npmGlobalPackages:
"react-native": Not Found
Android:
hermesEnabled: true
newArchEnabled: false
iOS:
hermesEnabled: Not found
newArchEnabled: Not found

Steps to reproduce

First I create an empty folder
mkdir monorepo && cd monorepo

I create a react native app
npx react-native@latest init AwesomeProject

I start lerna
lerna init

I create new package with lerna
lerna create package1

I modify packages/package1/package.js with this code:

import React from 'react';
import { Text, TouchableOpacity } from 'react-native';

export const CustomButton = ({ onPress, title }) => {
  return (
    <TouchableOpacity onPress={onPress}>
      <Text>{title}</Text>
    </TouchableOpacity>
  );
};

I run react native in RN project (still without adding the lerna package)

/monorepo/AwesomeProject$ npm start
/monorepo/AwesomeProject$ npm run android
  • The project runs correctly

I install my lerna package
/monorepo/AwesomeProject$ npm install ../packages/package1

I check that it has been installed in package.json

  "dependencies": {
    "package1": "file:../packages/package1",
    "react": "18.2.0",
    "react-native": "0.72.1"
  },

I go to App.tsx and import the package:
import {CustomButton} from 'package1';

And I use it:

  <View>
    <CustomButton
      title="Press me!"
      onPress={() => console.log('Hello!')}
    />
  </View>
Snack, code example, screenshot, or link to a repository

App.spx full code:

/**
 * Sample React Native App
 * https://github.com/facebook/react-native
 *
 * @format
 */

import React from 'react';
import type {PropsWithChildren} from 'react';
import {
  SafeAreaView,
  ScrollView,
  StatusBar,
  StyleSheet,
  Text,
  useColorScheme,
  View,
} from 'react-native';

import {
  Colors,
  DebugInstructions,
  Header,
  LearnMoreLinks,
  ReloadInstructions,
} from 'react-native/Libraries/NewAppScreen';
import {CustomButton} from 'package1';

type SectionProps = PropsWithChildren<{
  title: string;
}>;

function Section({children, title}: SectionProps): JSX.Element {
  const isDarkMode = useColorScheme() === 'dark';
  return (
    <View style={styles.sectionContainer}>
      <Text
        style={[
          styles.sectionTitle,
          {
            color: isDarkMode ? Colors.white : Colors.black,
          },
        ]}>
        {title}
      </Text>
      <Text
        style={[
          styles.sectionDescription,
          {
            color: isDarkMode ? Colors.light : Colors.dark,
          },
        ]}>
        {children}
      </Text>
    </View>
  );
}

function App(): JSX.Element {
  const isDarkMode = useColorScheme() === 'dark';

  const backgroundStyle = {
    backgroundColor: isDarkMode ? Colors.darker : Colors.lighter,
  };

  return (
    <SafeAreaView style={backgroundStyle}>
      <StatusBar
        barStyle={isDarkMode ? 'light-content' : 'dark-content'}
        backgroundColor={backgroundStyle.backgroundColor}
      />
      <ScrollView
        contentInsetAdjustmentBehavior="automatic"
        style={backgroundStyle}>
        <Header />
        <View
          style={{
            backgroundColor: isDarkMode ? Colors.black : Colors.white,
          }}>
          <Section title="Step One">
            Edit <Text style={styles.highlight}>App.tsx</Text> to change this
            screen and then come back to see your edits.
          </Section>
          <View>
            <CustomButton
              title="Press me!"
              onPress={() => console.log('Hello!')}
            />
          </View>
          <Section title="See Your Changes">
            <ReloadInstructions />
          </Section>
          <Section title="Debug">
            <DebugInstructions />
          </Section>
          <Section title="Learn More">
            Read the docs to discover what to do next:
          </Section>
          <LearnMoreLinks />
        </View>
      </ScrollView>
    </SafeAreaView>
  );
}

const styles = StyleSheet.create({
  sectionContainer: {
    marginTop: 32,
    paddingHorizontal: 24,
  },
  sectionTitle: {
    fontSize: 24,
    fontWeight: '600',
  },
  sectionDescription: {
    marginTop: 8,
    fontSize: 18,
    fontWeight: '400',
  },
  highlight: {
    fontWeight: '700',
  },
});

export default App;

Screen error:

Screenshot_1688972880

主要语言
JavaScript
星标
5.6k
派生
702
平均合并
3 天 2 小时
30 天内合并 PR
44

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

react/metro 的其他 Issue

查看 react/metro 的全部 Issue

相似的 Issue

更多 JavaScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。