You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Nx monorepo下Expo项目Release模式打包异常:useState引用丢失问题求助

Nx monorepo下Expo项目Release模式打包异常:useState引用丢失问题求助

大家好,我最近在Nx monorepo的Expo项目里遇到了个头疼的问题:Debug模式下项目运行完全正常,但构建Release版本安装包时,JS bundle似乎没正确打包,出现了useState引用不存在的错误。

以下是我的项目环境信息:

  • 包管理器:pnpm 10.10.0
  • Node.js版本:22.14.0
  • Expo版本:52.0.41
  • React Native版本:0.76.7
  • React版本:18.3.1
  • Nx相关依赖:@nx/expo 20.6.4、@nx/react-native 20.6.4
  • 构建命令:使用@nx/react-native:build-android生成Release版本
  • 样式工具链:nativewind 4.1.23、tailwindcss 3.4.17、react-native-css-interop@0.1.22

我的Metro配置文件

const { withNxMetro } = require('@nx/expo');
const { mergeConfig } = require('metro-config');
const { withNativeWind } = require('nativewind/metro');
const withStorybook = require('@storybook/react-native/metro/withStorybook');
const path = require('path');
const { getSentryExpoConfig } = require('@sentry/react-native/metro');

const defaultConfig = getSentryExpoConfig(__dirname);
const { assetExts, sourceExts } = defaultConfig.resolver;

/**
 * Metro configuration
 * https://reactnative.dev/docs/metro
 *
 * @type {import('metro-config').MetroConfig}
 */
const customConfig = {
  resolver: {
    assetExts: assetExts.filter((ext) => ext !== 'svg'),
    sourceExts: [...sourceExts, 'cjs', 'mjs', 'svg'],
  },
};

module.exports = withNxMetro(mergeConfig(defaultConfig, customConfig), {
  // Change this to true to see debugging info.
  // Useful if you have issues resolving modules
  debug: false,
  // all the file extensions used for imports other than 'ts', 'tsx', 'js', 'jsx', 'json'
  extensions: [],
  // Specify folders to watch, in addition to Nx defaults (workspace libraries and node_modules)
  watchFolders: [],
}).then((config) => withNativeWind(
  withStorybook(config, {
    enabled: true,
    configPath: path.resolve(__dirname, './.storybook'),
  }),
  { input: './global.css' }
));

我的Babel配置文件

module.exports = function (api) {
  api.cache(true);
  return {
    presets: [['babel-preset-expo', { jsxImportSource: 'nativewind' }], 'nativewind/babel'],
    plugins: ['react-native-reanimated/plugin'],
  };
};

有没有朋友遇到过类似的问题?或者能帮我排查下,是不是配置里有什么地方导致Release打包时丢失了React Hooks的引用?

内容来源于stack exchange

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.08 12:29:49