简体   繁体   English

React Native 错误找不到模块'metro-config/src/defaults/blacklist'

[英]React Native Error Cannot find module 'metro-config/src/defaults/blacklist'

I'm currently working on a project in React Native, yesterday it was working perfectly with no errors, and now all of a sudden I'm getting this error.我目前正在使用 React Native 开发一个项目,昨天它运行完美,没有任何错误,现在我突然遇到了这个错误。

error Cannot find module 'metro-config/src/defaults/blacklist'
Require stack:
- /Users/sri/Downloads/cc_x/reactnativelcsapp/VitalitiApp/metro.config.js

I've tried soo many solutions, removing the node modules and installing it back, updating the modules, looking to change the backlist.我尝试了很多解决方案,删除节点模块并将其重新安装,更新模块,寻找更改后备列表。 I've checked my files and I can't find the blacklist file but I'm trying to fix it but honestly have no idea how to fix it.我检查了我的文件,但找不到黑名单文件,但我正在尝试修复它,但老实说不知道如何修复它。 I was wondering if anyone would know what to do.我想知道是否有人会知道该怎么做。

the blacklist file seems to be renamed as exclusionList黑名单文件似乎被重命名为 excludeList

const blacklist = require('metro-config/src/defaults/exclusionList');

use this line instead in metro.config.js在metro.config.js 中使用这一行

I had the same Issue as others.我和其他人有同样的问题。 Changing it to将其更改为

const exclusionList = require('metro-config/src/defaults/exclusionList');

Fixed my issue.解决了我的问题。

I had to create metro.config.js and insert the following code since I was using AWS Amplify:我必须创建metro.config.js并插入以下代码,因为我使用的是 AWS Amplify:

const blacklist = require('metro-config/src/defaults/exclusionList');

module.exports = {
    resolver: {
        blacklistRE: blacklist([/amplify\/#current-cloud-backend\/.*/]),
    },
    transformer: {
        getTransformOptions: async () => ({
            transform: {
                experimentalImportSupport: false,
                inlineRequires: false,
            },
        }),
    },
};

In newer versions of metro-config the function is now called exclusionList .在新版本的metro-config中,该函数现在称为exclusionList So change the blacklist reference with exclusionList in metro-config.js file which is located in the project root directory.因此,使用项目根目录中的metro-config.js文件中的exclusionList更改blacklist引用。

const exclusionList = require('metro-config/src/defaults/exclusionList');

If still issue persists, then add metro-config as a dev dependency:如果问题仍然存在,则添加metro-config作为开发依赖项:

npm install -D metro-config

I had the same error in myapp/node_modules/expo-yarn-workspaces/index.js From my require stack so I opened this file and found const blacklist = require('metro-config/src/defaults/blacklist');我在myapp/node_modules/expo-yarn-workspaces/index.js中遇到了同样的错误来自我的 require 堆栈所以我打开这个文件并找到const blacklist = require('metro-config/src/defaults/blacklist'); into my app node modules.进入我的应用程序节点模块。

So I changed it to所以我把它改成了

const blacklist = require('metro-config/src/defaults/exclusionList');

which fixed my problem这解决了我的问题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 缺少包“metro-config”(React Native) - Missing package "metro-config" (React Native) 在 expo react-native 项目中找不到模块“metro/src/lib/TerminalReporter” - Cannot find module 'metro/src/lib/TerminalReporter' in expo react-native project 在现有 Nx 项目上创建 React 应用程序时找不到模块“nx/src/config/workspaces” - Cannot find module 'nx/src/config/workspaces' on creating a React app on existing Nx project React Native 无法 npx init 项目,找不到模块错误 - React Native cannot npx init project, cannot find module error 错误 - 找不到模块“config” - Error - Cannot find module 'config' 加载React Native:UnhandledPromiseRejectionWarning:错误:找不到模块'View' - Loading React Native: UnhandledPromiseRejectionWarning: Error: Cannot find module 'View' BABEL 找不到模块“节点:路径”错误 react-native - BABEL Cannot find module 'node:path' error react-native 错误:找不到模块“ reative-native” /未找到模块:错误:无法解析模块“ react-native-web” - Error: Cannot find module “react-native” / Module not found: Error: Cannot resolve module 'react-native-web' 更新 metro-config.js React Native - Updating metro-config.js React Native Expo - React Native - Metro 配置文件 - Expo - React Native - Metro Config File
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM