简体   繁体   English

错误:找不到模块“ reative-native” /未找到模块:错误:无法解析模块“ react-native-web”

[英]Error: Cannot find module “react-native” / Module not found: Error: Cannot resolve module 'react-native-web'

Alright, I am desperately trying to install a branch of react-native-web that has a functioning ListView component. 好吧,我拼命尝试安装一个具有功能性ListView组件的react-native-web分支。 This branch , specifically. 特别是这个分支

I installed it into the project directory like so: npm install --save react@0.14 react-dom@0.14 https://github.com/IjzerenHein/react-native-web/tarball/feaure-listview2 我将其安装到项目目录中,如下所示: npm install --save react@0.14 react-dom@0.14 https://github.com/IjzerenHein/react-native-web/tarball/feaure-listview2

Installing directly from react-native-web doesn't seem to have this issue. 直接从react-native-web安装似乎没有这个问题。

this is what index.web.js looks like: 这就是index.web.js的样子:

import React from 'react'

import {
AppRegistry,
Component,
...
} from 'react-native';

class App extends Component {
...
}

// App registration and rendering
AppRegistry.registerComponent('App', () => App);
AppRegistry.runApplication('App', { rootTag:     document.getElementById('react-root') });

Here is what the console tells me (part of it, way too much text in there!): 这是控制台告诉我的内容(部分原因,其中太多文本了!):

[Error] ./index.web.js
Module not found: Error: Cannot resolve module 'react-native-web' in /Users/michael/Code/spectrum-react-native
resolve module react-native-web in /Users/michael/Code/spectrum-react-native
  looking for modules in /Users/michael/Code/spectrum-react-native/node_modules
  resolve 'file' react-native-web in /Users/michael/Code/spectrum-react-native/node_modules
  resolve file
    /Users/michael/Code/spectrum-react-native/node_modules/react-native-web is not a file
    /Users/michael/Code/spectrum-react-native/node_modules/react-native-web.webpack.js doesn't exist
    /Users/michael/Code/spectrum-react-native/node_modules/react-native-web.web.js doesn't exist
    /Users/michael/Code/spectrum-react-native/node_modules/react-native-web.js doesn't exist
    /Users/michael/Code/spectrum-react-native/node_modules/react-native-web.json doesn't exist
resolve 'file' or 'directory' /Users/michael/Code/spectrum-react-native/node_modules/react-native-web
  resolve file
    /Users/michael/Code/spectrum-react-native/node_modules/react-native-web is not a file
    /Users/michael/Code/spectrum-react-native/node_modules/react-native-web.webpack.js doesn't exist
    /Users/michael/Code/spectrum-react-native/node_modules/react-native-web.web.js doesn't exist
    /Users/michael/Code/spectrum-react-native/node_modules/react-native-web.js doesn't exist
    /Users/michael/Code/spectrum-react-native/node_modules/react-native-web.json doesn't exist
  resolve directory
    directory default file index
      resolve file index in /Users/michael/Code/spectrum-react-native/node_modules/react-native-web
        /Users/michael/Code/spectrum-react-native/node_modules/react-native-web/index doesn't exist
        /Users/michael/Code/spectrum-react-native/node_modules/react-native-web/index.webpack.js doesn't exist
        /Users/michael/Code/spectrum-react-native/node_modules/react-native-web/index.web.js doesn't exist
        /Users/michael/Code/spectrum-react-native/node_modules/react-native-web/index.js doesn't exist
        /Users/michael/Code/spectrum-react-native/node_modules/react-native-web/index.json doesn't exist
    use dist/index.js from package.json
      resolve 'file' or 'directory' dist/index.js in /Users/michael/Code/spectrum-react-native/node_modules/react-native-web
        resolve file
          /Users/michael/Code/spectrum-react-native/node_modules/react-native-web/dist/index.js doesn't exist
          /Users/michael/Code/spectrum-react-native/node_modules/react-native-web/dist/index.js.webpack.js doesn't exist
          /Users/michael/Code/spectrum-react-native/node_modules/react-native-web/dist/index.js.web.js doesn't exist
          /Users/michael/Code/spectrum-react-native/node_modules/react-native-web/dist/index.js.js doesn't exist
          /Users/michael/Code/spectrum-react-native/node_modules/react-native-web/dist/index.js.json doesn't exist
        resolve directory
          /Users/michael/Code/spectrum-react-native/node_modules/react-native-web/dist/index.js doesn't exist (directory default file)
          /Users/michael/Code/spectrum-react-native/node_modules/react-native-web/dist/index.js/package.json doesn't exist (directory description file)
  ...

 @ ./index.web.js 9:19-42
errors (bundle.js:7934)
onmessage (bundle.js:7969)
dispatchEvent (bundle.js:2874)
(anonymous function) (bundle.js:4908)
forEach
_transportMessage (bundle.js:4906)
(anonymous function)
emit (bundle.js:847)
onmessage (bundle.js:6261)

The problem is, that they have a build process. 问题是,他们有一个构建过程。 That way there are files used / expected that are ignored in git, but within the npm export. 这样一来,在git中,但在npm导出中,会使用/预期会忽略的文件。

The easiest way to overcome this is to clone the repository, check out the given branch, run the build and depending on if you have a large team either use npm link to link the local repository or remove dist/ from the .gitignore and push the build files to the branch. 解决此问题的最简单方法是克隆存储库,签出给定的分支,运行构建,然后根据您是否有大型团队使用npm link来链接本地存储库或从.gitignore删除dist/并推送将文件生成到分支。

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

相关问题 BABEL 找不到模块“节点:路径”错误 react-native - BABEL Cannot find module 'node:path' error react-native 找不到模块'setupDevtools'React-Native - Cannot find module 'setupDevtools' React-Native 找不到模块'react-native' - Cannot Find Module 'react-native' 将React-Navigation与react-native-web一起使用会引发错误,因为它无法导入与Web相关的模块 - Using React-Navigation with react-native-web throws me error because it cannot import web related module React Native 无法 npx init 项目,找不到模块错误 - React Native cannot npx init project, cannot find module error Flow react native 导入图片错误无法解析模块RelativeImageStub - Flow react native import image error cannot resolve module RelativeImageStub 错误:index.js: [BABEL]: 在 react-native 中找不到模块 'node:fs' - error: index.js: [BABEL]: Cannot find module 'node:fs' in react-native 加载React Native:UnhandledPromiseRejectionWarning:错误:找不到模块'View' - Loading React Native: UnhandledPromiseRejectionWarning: Error: Cannot find module 'View' react-native 如何解决“无法解析模块...”错误? - How to solve "Unable to resolve module..." error with react-native? 找不到模块:错误:无法解析模块“react-redux” - Module not found: Error: Cannot resolve module 'react-redux'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM