簡體   English   中英

錯誤:找不到模塊“ reative-native” /未找到模塊:錯誤:無法解析模塊“ react-native-web”

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

好吧,我拼命嘗試安裝一個具有功能性ListView組件的react-native-web分支。 特別是這個分支

我將其安裝到項目目錄中,如下所示: npm install --save react@0.14 react-dom@0.14 https://github.com/IjzerenHein/react-native-web/tarball/feaure-listview2

直接從react-native-web安裝似乎沒有這個問題。

這就是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') });

這是控制台告訴我的內容(部分原因,其中太多文本了!):

[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)

問題是,他們有一個構建過程。 這樣一來,在git中,但在npm導出中,會使用/預期會忽略的文件。

解決此問題的最簡單方法是克隆存儲庫,簽出給定的分支,運行構建,然后根據您是否有大型團隊使用npm link來鏈接本地存儲庫或從.gitignore刪除dist/並推送將文件生成到分支。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM