React-Native 找不到存在的 Node_modules。这可能只在我使用纱线工作区时发生

Kur*_*ini 6 react-native monorepo yarnpkg

为了添加它,我运行了以下命令:

yarn workspace mobile add react-native-webview
Run Code Online (Sandbox Code Playgroud)

我确实查看了下面的错误所指定的node_modules文件夹,并且react-native-webview显然在那里。然而,仍然总是抛出这个错误?我什至执行了红色错误屏幕上的反应本机轮廓的步骤,该屏幕显示模块显示为缺失但实际上存在。

Error: Unable to resolve module `react-native-webview` from `index.js`: react-native-webview could not be found within the project or in these directories:
  ../../node_modules
  /Users/kurnalsaini/Documents/test-mono/packages/mobile/node_modules
Run Code Online (Sandbox Code Playgroud)

我是否应该修改我的 Metro-config 文件或其他一些配置文件才能使其正常工作?因为对我来说,令人难以置信的是,它告诉它正在查找正确的文件夹,但仍然说它不存在。

Moh*_*nji 1

尝试设置您的 Metro 配置以监视错误中显示的目录中的 node_modules,您的 Metro.config.js 应如下所示: const path = require("path");

    const watchFolders = [
      //Relative path to packages directory
      path.resolve(__dirname + "/.."),
      path.resolve(__dirname + "/../../node_modules"),
    ];
    
    module.exports = {
      resetCache: true,
      transformer: {
        getTransformOptions: async () => ({
          transform: {
            experimentalImportSupport: false,
            inlineRequires: false,
          },
        }),
      },
      watchFolders,
    };
Run Code Online (Sandbox Code Playgroud)