gpt4 book ai didi

javascript - 错误 : Cannot find module "react-native"/Module not found: Error: Cannot resolve module 'react-native-web'

转载 作者:行者123 更新时间:2023-11-29 17:57:12 34 4
gpt4 key购买 nike

好吧,我拼命地尝试安装一个具有正常运行的 ListView 组件的 react-native-web 分支。 This branch ,特别是。

我像这样将它安装到项目目录中: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/ 并将构建文件推送到分支。

关于javascript - 错误 : Cannot find module "react-native"/Module not found: Error: Cannot resolve module 'react-native-web' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38026036/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com