0
votes

I'm trying to run the command "npx react-native start" and shows this error

error Cannot find module '@expo/metro-config'
Require stack:
- D:\Projetos\apporto\metro.config.js
- D:\Projetos\apporto\node_modules\cosmiconfig\node_modules\import-fresh\index.js
- D:\Projetos\apporto\node_modules\cosmiconfig\dist\loaders.js
- D:\Projetos\apporto\node_modules\cosmiconfig\dist\createExplorer.js
- D:\Projetos\apporto\node_modules\cosmiconfig\dist\index.js
- D:\Projetos\apporto\node_modules\@react-native-community\cli\build\tools\config\readConfigFromDisk.js
- D:\Projetos\apporto\node_modules\@react-native-community\cli\build\tools\config\index.js
- D:\Projetos\apporto\node_modules\@react-native-community\cli\build\commands\install\install.js
- D:\Projetos\apporto\node_modules\@react-native-community\cli\build\commands\index.js
- D:\Projetos\apporto\node_modules\@react-native-community\cli\build\index.js
- D:\Projetos\apporto\node_modules\@react-native-community\cli\build\bin.js
Error: Cannot find module '@expo/metro-config'
Require stack:
- D:\Projetos\apporto\metro.config.js
- D:\Projetos\apporto\node_modules\cosmiconfig\node_modules\import-fresh\index.js
- D:\Projetos\apporto\node_modules\cosmiconfig\dist\loaders.js
- D:\Projetos\apporto\node_modules\cosmiconfig\dist\createExplorer.js
- D:\Projetos\apporto\node_modules\cosmiconfig\dist\index.js
- D:\Projetos\apporto\node_modules\@react-native-community\cli\build\tools\config\readConfigFromDisk.js
- D:\Projetos\apporto\node_modules\@react-native-community\cli\build\tools\config\index.js
- D:\Projetos\apporto\node_modules\@react-native-community\cli\build\commands\install\install.js
- D:\Projetos\apporto\node_modules\@react-native-community\cli\build\commands\index.js
- D:\Projetos\apporto\node_modules\@react-native-community\cli\build\index.js
- D:\Projetos\apporto\node_modules\@react-native-community\cli\build\bin.js
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:924:15)
    at Function.Module._load (node:internal/modules/cjs/loader:769:27)
    at Module.require (node:internal/modules/cjs/loader:996:19)
    at require (node:internal/modules/cjs/helpers:92:18)
    at Object.<anonymous> (D:\Projetos\apporto\metro.config.js:1:30)
    at Module._compile (node:internal/modules/cjs/loader:1092:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1121:10)
    at Module.load (node:internal/modules/cjs/loader:972:32)
    at Function.Module._load (node:internal/modules/cjs/loader:813:14)
    at Module.require (node:internal/modules/cjs/loader:996:19)

I try to use the npm i metro-config --save-dev but doesn't work.

I don't know what to do.

#################### package.json ###############################

{ "name": "apporto", "version": "0.0.1", "private": true, "scripts": { "android": "react-native run-android", "ios": "react-native run-ios", "start": "react-native start", "test": "jest", "lint": "eslint ." }, "dependencies": { "@react-native-community/async-storage": "^1.12.1", "@react-native-community/geolocation": "^2.0.2", "@react-native-community/masked-view": "^0.1.10", "@react-navigation/bottom-tabs": "^5.11.9", "@react-navigation/native": "^5.9.4", "@react-navigation/stack": "^5.14.4", "react": "17.0.1", "react-native": "0.64.0", "react-native-gesture-handler": "^1.10.3", "react-native-permissions": "^3.0.1", "react-native-reanimated": "^2.1.0", "react-native-safe-area-context": "^3.2.0", "react-native-screens": "^3.1.1", "react-native-svg": "*", "react-native-svg-transformer": "^0.14.3", "react-native-swiper": "^1.6.0", "styled-components": "^5.2.3" }, "devDependencies": { "@babel/core": "^7.12.9", "@babel/runtime": "^7.12.5", "@react-native-community/eslint-config": "^2.0.0", "babel-jest": "^26.6.3", "eslint": "7.14.0", "jest": "^26.6.3", "metro-config": "^0.64.0", "metro-react-native-babel-preset": "^0.64.0", "react-test-renderer": "17.0.1" }, "jest": { "preset": "react-native" } }

4
please post your package.json file contentsCornel Raiu
why don't you just edit the question and add it there?Cornel Raiu
@CornelRaiu sorry, it's my first time using here.Mário Sérgio

4 Answers

2
votes

After installing expo/metro-config:

npm i @expo/metro-config

Go to metro.config.js change:

const { getDefaultConfig } = require('expo/metro-config');

To:

const { getDefaultConfig } = require('@expo/metro-config');

It works for me. Thanks

0
votes

I had the same issue, I downloaded expo metro config and that fixed the issue

npm i @expo/metro-config
0
votes

The expo config file has been missing from here. Run

npm i @expo/metro-config

In the main folder update the

metro.config.js

Change the following line

const { getDefaultConfig } = require('expo/metro-config');

to

const { getDefaultConfig } = require('@expo/metro-config');

Works like a Charm!

-1
votes

{
"name": "metro-config",
"version": "0.64.0",
"description": "🚇 Config parser for Metro.",
"main": "src/index.js",
"repository": {
"type": "git",
"url": "[email protected]:facebook/metro.git"
},
"scripts": {
"prepare-release": "test -d build && rm -rf src.real && mv src src.real && mv build src",
"cleanup-release": "test ! -e build && mv src build && mv src.real src" },
"license": "MIT",
"dependencies": {
"cosmiconfig": "^5.0.5",
"jest-validate": "^26.5.2",
"metro": "0.64.0",
"metro-cache": "0.64.0",
"metro-core": "0.64.0",
"metro-runtime": "0.64.0"
},
"devDependencies": {
"pretty-format": "^26.5.2",
"strip-ansi": "^6.0.0"
}
}