错误:尝试从文件解析模块“属性类型”时

时间:2019-03-30 11:30:16

标签: react-native react-redux react-proptypes

我运行命令react-native run-android时出错。该错误发生在Metro bundler上,该应用正在我的设备上安装时,始终显示此错误。

奇怪的是,只有我在这台PC上发生过,我使用了很长时间,当我在这里拉git repo时(以前我也能够在该PC上进行开发和测试),所以不可能得到它为这个错误工作...

我想也许是我几天前删除了yarn.lock,当我运行npm install时会产生此错误吗?

出于逻辑原因,我省略了路径:

Loading dependency graph, done.
error: bundling failed: Error: While trying to resolve module `prop-types` from file `PATH_TO_PROJECT_FOLDER\node_modules\react-redux\lib\components\Provider.js`, the package `PATH_TO_PROJECT_FOLDER\node_modules\react-redux\node_modules\prop-types\package.json` was successfully found. However, this package itself specifies a `main` module field that could not be resolved (`PATH_TO_PROJECT_FOLDER\node_modules\react-redux\node_modules\prop-types\index`. Indeed, none of these files exist:

  * `PATH_TO_PROJECT_FOLDER\node_modules\react-redux\node_modules\prop-types\index(.native||.android.js|.native.js|.js|.android.json|.native.json|.json|.android.ts|.native.ts|.ts|.android.tsx|.native.tsx|.tsx)`
  * `PATH_TO_PROJECT_FOLDER\node_modules\react-redux\node_modules\prop-types\index\index(.native||.android.js|.native.js|.js|.android.json|.native.json|.json|.android.ts|.native.ts|.ts|.android.tsx|.native.tsx|.tsx)`
    at ResolutionRequest.resolveDependency (PATH_TO_PROJECT_FOLDER\node_modules\metro\src\node-haste\DependencyGraph\ResolutionRequest.js:65:15)
    at DependencyGraph.resolveDependency (PATH_TO_PROJECT_FOLDER\node_modules\metro\src\node-haste\DependencyGraph.js:283:16)
    at Object.resolve (PATH_TO_PROJECT_FOLDER\node_modules\metro\src\lib\transformHelpers.js:261:42)
    at dependencies.map.result (PATH_TO_PROJECT_FOLDER\node_modules\metro\src\DeltaBundler\traverseDependencies.js:399:31)
    at Array.map (<anonymous>)
    at resolveDependencies (PATH_TO_PROJECT_FOLDER\node_modules\metro\src\DeltaBundler\traverseDependencies.js:396:18)
    at PATH_TO_PROJECT_FOLDER\node_modules\metro\src\DeltaBundler\traverseDependencies.js:269:33
    at Generator.next (<anonymous>)
    at asyncGeneratorStep (PATH_TO_PROJECT_FOLDER\node_modules\metro\src\DeltaBundler\traverseDependencies.js:87:24)
    at _next (PATH_TO_PROJECT_FOLDER\node_modules\metro\src\DeltaBundler\traverseDependencies.js:107:9)
 DELTA  [android, dev] ..\..\../index.android.js ▓▓▓▓▓▓▓▓░░░░░░░░ 51.9% (610/847), failed.

本机:0.59.1

react-native-cli:2.0.1

1 个答案:

答案 0 :(得分:1)

好吧。我不应该删除yarn.lock文件。

要解决:

  1. 按照@ hend-el-sahli的说明删除根文件夹项目上的所有.lock文件。
  2. yarn install
  3. 如果您遇到错误unable to resolve module ./index,请查看该线程https://github.com/facebook/react-native/issues/24112

:)