【发布时间】:2015-11-19 04:13:24
【问题描述】:
react-native 提及的变更日志 https://facebook.github.io/react/blog/2015/04/17/react-native-v0.4.html
NPM 模块兼容性:NPM 上有很多不依赖于节点/浏览器内部的库,这些库在 React Native 中非常有用,例如 superagent、下划线……
但这对我不起作用。 这就是我通过 package.json 安装的方式
# package.json
"dependencies": {
"react-native": "*",
"underscore": "^1.8.3"
...
我确实在 npm 依赖中看到了它
# npm ls
├─┬ react-native@0.8.0
| ...
├── react-native-navbar@0.7.3
└── underscore@1.8.3
它确实适用于其他一些反应组件
这就是我的要求
var _ = require('underscore');
但是不行,_是未定义的
【问题讨论】:
-
你在同一个文件中使用它吗?你能在你的问题中粘贴一些代码吗?
-
不,
underscore库在node_modules文件夹下,我使用的其他库如react-native-keyboardevents、react-native-navbar都在node_modules下。但他们工作。我不知道它们有什么区别 -
1.也许您正试图从不同的文件中使用它?没有包含
underscore的文件? 2.也许尝试使用浏览器的断点。 cmd +d 在您的模拟器中并使用源选项卡进行调试。 -
我在每个文件中都试过了,但是没有用。我在控制台中调试了这个和
require('underscore'),它返回Error: Requiring unknown module "underscore". If you are sure the module is there, try restarting the packager.,我做到了(关闭并重新启动npm)。但它仍然失败。