Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

当项目路径中包含 react-native 时 , rn 启动失败 #11988

Closed
foolishchow opened this issue Jun 24, 2022 · 0 comments
Closed

当项目路径中包含 react-native 时 , rn 启动失败 #11988

foolishchow opened this issue Jun 24, 2022 · 0 comments
Labels
F-react Framework - React T-rn Target - 编译到 React Native V-3 Version - 3.x

Comments

@foolishchow
Copy link
Contributor

foolishchow commented Jun 24, 2022

相关平台

React Native

使用框架: React

复现步骤

taro init react-native-xxx
npm run dev:rn

期望结果

启动rn

实际结果

RuntimeError: abort(Error: ENOENT: no such file or directory, open '/Users/xxx/Desktop/react-native/package.json'). Build with -s ASSERTIONS=1 for more info.
    at process.abort (/Users/xxx/Desktop/react-native/cross-platform-demo/node_modules/metro-hermes-compiler/src/emhermesc.js:440:13)
    at process.emit (node:events:390:28)
    at emit (node:internal/process/promises:136:22)
    at processPromiseRejections (node:internal/process/promises:242:25)
    at processTicksAndRejections (node:internal/process/task_queues:97:32)
error Command failed with exit code 7.

环境信息

aro CLI 3.3.17 environment info:
    System:
      OS: macOS 11.4
      Shell: 5.8 - /bin/zsh
    Binaries:
      Node: 16.13.0 - ~/.nvm/versions/node/v16.13.0/bin/node
      Yarn: 1.22.17 - ~/.nvm/versions/node/v16.13.0/bin/yarn
      npm: 8.1.0 - ~/.nvm/versions/node/v16.13.0/bin/npm
    npmPackages:
      @tarojs/components: 3.4.12 => 3.4.12 
      @tarojs/mini-runner: 3.4.12 => 3.4.12 
      @tarojs/react: 3.4.12 => 3.4.12 
      @tarojs/runtime: 3.4.12 => 3.4.12 
      @tarojs/taro: 3.4.12 => 3.4.12 
      @tarojs/webpack-runner: 3.4.12 => 3.4.12 
      babel-preset-taro: 3.4.12 => 3.4.12 
      eslint-config-taro: 3.4.12 => 3.4.12 
      react: ^17.0.2 => 17.0.2 
      react-native: ^0.66.0 => 0.66.4 
    npmGlobalPackages:
      typescript: 4.6.3

补充信息

问题代码

const splittings = rnBasePath.split(path.sep)
const index = splittings.indexOf(reactNativeModuleName)
return splittings.slice(0, index + 1).join(path.sep)

这个代码应该改为

const splittings = rnBasePath.split(path.sep) 
const index = splittings.lastIndexOf(reactNativeModuleName);
return splittings.slice(0, index + 1).join(path.sep) 
// 或者
return path.dirname(rnBasePath)
@taro-bot2 taro-bot2 bot added F-react Framework - React T-rn Target - 编译到 React Native V-3 Version - 3.x labels Jun 24, 2022
foolishchow added a commit to foolishchow/taro that referenced this issue Jun 27, 2022
fix wrong react-native path when project dir contains react-native
zhiqingchen pushed a commit that referenced this issue Jun 27, 2022
fix wrong react-native path when project dir contains react-native
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
F-react Framework - React T-rn Target - 编译到 React Native V-3 Version - 3.x
Projects
None yet
Development

No branches or pull requests

2 participants