Zakiberbullenii
@Zakiberbullenii

Почему react native не может resolve'ить react-redux?

Делал приложение на react-native на expo с помощью react-redux, всегда было все нормально, redux работал и react-native Не ругался, но почему-то в этот раз он начал выводить ошибку:
Unable to resolve "react-redux" from "App.tsx"

и:
[Error: InternalError Metro has encountered an error: While trying to resolve module `react-redux` from file `E:\Code\eggs-calc\eggs-calc\App.tsx`, the package `E:\Code\eggs-calc\eggs-calc\node_modules\react-redux\package.json` was successfully found. However, this package itself specifies a `main` module field that could not be resolved (`E:\Code\eggs-calc\eggs-calc\node_modules\react-redux\lib\index.js`. Indeed, none of these files exist:

* E:\Code\eggs-calc\eggs-calc\node_modules\react-redux\lib\index.js(.native|.android.ts|.native.ts|.ts|.android.tsx|.native.tsx|.tsx|.android.js|.native.js|.js|.android.jsx|.native.jsx|.jsx|.android.json|.native.json|.json)
* E:\Code\eggs-calc\eggs-calc\node_modules\react-redux\lib\index.js\index(.native|.android.ts|.native.ts|.ts|.android.tsx|.native.tsx|.tsx|.android.js|.native.js|.js|.android.jsx|.native.jsx|.jsx|.android.json|.native.json|.json): E:\Code\eggs-calc\eggs-calc\node_modules\metro\src\node-haste\DependencyGraph.js (243:17)

241 |
242 | if (error instanceof InvalidPackageError) {
> 243 | throw new PackageResolutionError({
| ^
244 | packageError: error,
245 | originModulePath: from,
246 | targetModuleName: to,]
Error: While trying to resolve module `react-redux` from file `E:\Code\eggs-calc\eggs-calc\App.tsx`, the package `E:\Code\eggs-calc\eggs-calc\node_modules\react-redux\package.json` was successfully found. However, this package itself specifies a `main` module field that could not be resolved (`E:\Code\eggs-calc\eggs-calc\node_modules\react-redux\lib\index.js`. Indeed, none of these files exist:

* E:\Code\eggs-calc\eggs-calc\node_modules\react-redux\lib\index.js(.native|.android.ts|.native.ts|.ts|.android.tsx|.native.tsx|.tsx|.android.js|.native.js|.js|.android.jsx|.native.jsx|.jsx|.android.json|.native.json|.json)
* E:\Code\eggs-calc\eggs-calc\node_modules\react-redux\lib\index.js\index(.native|.android.ts|.native.ts|.ts|.android.tsx|.native.tsx|.tsx|.android.js|.native.js|.js|.android.jsx|.native.jsx|.jsx|.android.json|.native.json|.json)
at DependencyGraph.resolveDependency (E:\Code\eggs-calc\eggs-calc\node_modules\metro\src\node-haste\DependencyGraph.js:243:17)
at Object.resolve (E:\Code\eggs-calc\eggs-calc\node_modules\metro\src\lib\transformHelpers.js:129:24)
at resolve (E:\Code\eggs-calc\eggs-calc\node_modules\metro\src\DeltaBundler\traverseDependencies.js:396:33)
at E:\Code\eggs-calc\eggs-calc\node_modules\metro\src\DeltaBundler\traverseDependencies.js:412:26
at Array.reduce ()
at resolveDependencies (E:\Code\eggs-calc\eggs-calc\node_modules\metro\src\DeltaBundler\traverseDependencies.js:411:33)
at processModule (E:\Code\eggs-calc\eggs-calc\node_modules\metro\src\DeltaBundler\traverseDependencies.js:140:31)
at async traverseDependenciesForSingleFile (E:\Code\eggs-calc\eggs-calc\node_modules\metro\src\DeltaBundler\traverseDependencies.js:131:3)
at async traverseDependencies (E:\Code\eggs-calc\eggs-calc\node_modules\metro\src\DeltaBundler\traverseDependencies.js:60:7)
at async DeltaCalculator._getChangedDependencies (E:\Code\eggs-calc\eggs-calc\node_modules\metro\src\DeltaBundler\DeltaCalculator.js:204:42)
Error: While trying to resolve module `react-redux` from file `E:\Code\eggs-calc\eggs-calc\App.tsx`, the package `E:\Code\eggs-calc\eggs-calc\node_modules\react-redux\package.json` was successfully found. However, this package itself specifies a `main` module field that could not be resolved (`E:\Code\eggs-calc\eggs-calc\node_modules\react-redux\lib\index.js`. Indeed, none of these files exist:

* E:\Code\eggs-calc\eggs-calc\node_modules\react-redux\lib\index.js(.native|.android.ts|.native.ts|.ts|.android.tsx|.native.tsx|.tsx|.android.js|.native.js|.js|.android.jsx|.native.jsx|.jsx|.android.json|.native.json|.json)
* E:\Code\eggs-calc\eggs-calc\node_modules\react-redux\lib\index.js\index(.native|.android.ts|.native.ts|.ts|.android.tsx|.native.tsx|.tsx|.android.js|.native.js|.js|.android.jsx|.native.jsx|.jsx|.android.json|.native.json|.json)
at DependencyGraph.resolveDependency (E:\Code\eggs-calc\eggs-calc\node_modules\metro\src\node-haste\DependencyGraph.js:243:17)
at Object.resolve (E:\Code\eggs-calc\eggs-calc\node_modules\metro\src\lib\transformHelpers.js:129:24)
at resolve (E:\Code\eggs-calc\eggs-calc\node_modules\metro\src\DeltaBundler\traverseDependencies.js:396:33)
at E:\Code\eggs-calc\eggs-calc\node_modules\metro\src\DeltaBundler\traverseDependencies.js:412:26
at Array.reduce ()
at resolveDependencies (E:\Code\eggs-calc\eggs-calc\node_modules\metro\src\DeltaBundler\traverseDependencies.js:411:33)
at processModule (E:\Code\eggs-calc\eggs-calc\node_modules\metro\src\DeltaBundler\traverseDependencies.js:140:31)
at async traverseDependenciesForSingleFile (E:\Code\eggs-calc\eggs-calc\node_modules\metro\src\DeltaBundler\traverseDependencies.js:131:3)
at async traverseDependencies (E:\Code\eggs-calc\eggs-calc\node_modules\metro\src\DeltaBundler\traverseDependencies.js:60:7)
at async DeltaCalculator._getChangedDependencies (E:\Code\eggs-calc\eggs-calc\node_modules\metro\src\DeltaBundler\DeltaCalculator.js:204:42)

в чем может быть проблема?
  • Вопрос задан
  • 155 просмотров
Решения вопроса 1
@laite
Привет, мне помогло создание файла в корне проекта 'metro.config.js'
и добавление туда
const { getDefaultConfig } = require('expo/metro-config');

const defaultConfig = getDefaultConfig(__dirname);

defaultConfig.resolver.sourceExts.push('mjs');

module.exports = defaultConfig;
Ответ написан
Комментировать
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Похожие вопросы