简体   繁体   English

NPM模块从/ Users / node_modules /而不是项目目录中获取

[英]NPM modules get required from /Users/node_modules/ instead of the project directory

My react-native project has been working well until I upgraded react-native from 0.17 to 0.18 and then 0.19. 我的本机项目一直运行良好,直到我将本机从0.17升级到0.18,然后再升级到0.19。

Ever since the upgrade any module (eg app-module-path) that I: 自升级以来,我执行的任何模块(例如,app-module-path):

  1. successfully install using npm - npm install --save app-module-path 使用npm成功安装npm install --save app-module-path

  2. add require('app-module-path').addPath(__dirname); 添加require('app-module-path').addPath(__dirname); in my code 在我的代码中

give the following error when running the simulator: 运行模拟器时给出以下错误:

Unable to resolve module from /Users/MyUserName/myfolder/projectname/node_modules/app-module-path/lib/index.js: Invalid directory /Users/node_modules/module

It seems it is looking for the module in the wrong path. 似乎是在错误的路径中寻找模块。 I tried to clear all the caches, uninstall an reinstall react-native, rebooted my machine after that and even started a clean project from scratch and the problem persists. 我试图清除所有缓存,卸载重新安装的react-native,然后重启机器,甚至从头开始启动一个干净的项目,问题仍然存在。

I have already tried all the solutions posted on the official issue without any luck: https://github.com/facebook/react-native/issues/4968 我已经尝试过在官方问题上发布的所有解决方案,没有任何运气: https : //github.com/facebook/react-native/issues/4968

npm: 3.3.12 React-Native: 0.19 OSX: 10.11.2 watchman: stable 4.1.0 (bottled), HEAD npm:3.3.12 React-Native:0.19 OSX:10.11.2值班员:稳定的4.1.0(瓶装),HEAD

I am looking for any type of solution that fixes my environment without loosing my code and all the integrations I have made in the XCode and Android projects to add some of the modules. 我正在寻找能够解决环境问题的任何类型的解决方案,而不会丢失我的代码以及我在XCode和Android项目中所做的所有集成以添加一些模块。

Thank you very much in advance! 提前非常感谢您!

Node js have group of possible folders that can contain modules. Node js有一组可能包含模块的文件夹。 When you install one module sometimes module can be dependent to other modules. 当您安装一个模块时,有时模块可以依赖于其他模块。 You have to install this dependancies manual. 您必须安装此相关性手册。 For example if the error is like /Users/node_modules/module you have to install "npm install -S module". 例如,如果错误类似于/ Users / node_modules / module,则必须安装“ npm install -S module”。 It is showing error as missing path in /Users/node_modules because this is the last element of array full with possible paths that can contain modules (for MAC). 它在/ Users / node_modules中显示为缺少路径的错误,因为这是阵列中的最后一个元素,具有可能包含模块的可能路径(对于MAC)。

Full list of paths by OS : https://www.npmjs.com/package/npm-paths 操作系统的完整路径列表: https : //www.npmjs.com/package/npm-paths

It seems many are having this issue with no solution: 似乎许多人都遇到这个问题,但没有解决方案:

https://github.com/facebook/react-native/issues/4968 https://github.com/facebook/react-native/issues/4968

I cannot install and use any additional npm packages as a module. 我无法安装和使用任何其他npm软件包作为模块。

The module path is correct. 模块路径正确。 I cut and paste the path displayed in xcode into a terminal to test path was valid and correct. 我将xcode中显示的路径剪切并粘贴到终端中,以测试路径是否正确。

Using: 使用方法:

  • OS X 10.11.3 OS X 10.11.3
  • npm 3.3.12 npm 3.3.12
  • node v5.5.0 节点v5.5.0
  • react-native-cli: 0.1.10 react-native-cli:0.1.10
  • react-native: 0.21.0 反应本机:0.21.0
  • xcode 7.2.1 Xcode的7.2.1

No work-arounds helped including: 没有解决方法,包括:

  • npm3 npm3
  • rm -rf node_modules rm -rf node_modules
  • npm start from ./node_modules/react-native. npm从./node_modules/react-native开始。
  • watchman watch-del-all 守望者
  • rm -fr $TMPDIR/react-* rm -fr $ TMPDIR /反应-*
  • npm cache clean && npm npm缓存清理&& npm
  • install Creating a new project from scratch 从头开始创建一个新项目
  • Modifying react-native/packager/react-packager/src/Resolver/index.js:98 修改react-native / packager / react-packager / src / Resolver / index.js:98

    -shouldThrowOnUnresolvedErrors: (, platform) => platform === 'ios', +shouldThrowOnUnresolvedErrors: (, platform) => { return false; -shouldThrowOnUnresolvedErrors:(,platform)=> platform ==='ios',+ shouldThrowOnUnresolvedErrors:(,platform)=> {return false; }, },

How does anyone get any work done in react-native without using additional npm packages? 在不使用其他npm软件包的情况下,任何人如何在react-native中完成任何工作?

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM