节点程序包对IBM Cloud Foundry的依赖关系-需求/模块未定义(程序包未加载) [英] Node package dependencies on IBM Cloud Foundry - require/module is not defined (Package not loading)

查看:84
本文介绍了节点程序包对IBM Cloud Foundry的依赖关系-需求/模块未定义(程序包未加载)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在通过IBM Cloud上的工具链工具来开发应用程序,并通过Eclipse Orion IDE编辑代码。由于我不是通过本地cli访问此文件,因此我的理解是,为了调用 npm install {package} ,我只需要将该软件包包括在 package.json 文件在依赖项下,需要在我的应用中。但是,当我加载应用程序时,未得到需求的定义,表明该软件包尚未安装。此外,在 app.js 文件中使用了 require(),并启动了应用程序,但没有从文件中启动在我的 public 目录中。

I am working on an application via the toolchain tool on IBM Cloud and editing the code via the Eclipse Orion IDE. As I am not accessing this through my local cli, my understanding is that in order to so call npm install {package}, I would just need to include the package in the package.json file under dependencies and require it in my app. However, when I load the application, I get the require is not defined indicating that the package has not been installed. Moreover, the require() is being used in the app.js file with the application being launched but not from files in my public directory.

进一步研究之后,似乎可能与目录的方式有关由于仅在子目录中引发错误,因此正在跟踪树。例如, require('express')在主目录<$ c $中的 app.js 中工作c> ./ ,但是在 ./ subdirectory / test.js中的 test.js 中调用时失败。 code>。我感觉好像缺少了一些非常简单的东西,例如端点的配置或其他东西。

After playing around further, it seems it might have to do with the way the directory tree is being traced as the error is only thrown in subdirectories. For example, require('express') works in app.js which is in the main directory ./ but fails when it is called in test.js in ./subdirectory/test.js. I feel like I'm missing something painfully simple like configuration of endpoint or something.

我一直在搜寻,但似乎找不到如何获得装入程序包,最好不使用cli。感谢任何指针。谢谢!

I've been searching around but I can't seem to find how to get the packages loaded, preferably without using the cli. Appreciate any pointers. Thanks!

更新:经过进一步研究,尝试从同一目录中的另一个文件进行请求时,我也得到模块未定义的错误。例如, module.exports =‘str’返回此错误。尝试 require(’./ file’)时,未定义需求。

Update: After playing around further, I am also getting module is not defined error when trying to require from another file in the same directory. For example module.exports = 'str' returns this error. While trying to require('./file') returns the require is not defined. It might have to do with how node is wrapping the functions?

更新2:尝试 start: npm install&&节点 app.js 放在 package.json 中,但是没有运气。添加一个在部署之前调用 npm install 的构建阶段也不起作用

Update 2: Tried "start": "npm install && node app.js" in package.json but no luck. Adding a build stage which calls npm install before deployment also does not work

更新3:添加<$ c之后在$ c> npm install 构建阶段,我可以看到已经通过日志成功构建了依赖项。但是,require未定义错误仍然存​​在。

Update 3: After adding npm install build stage, I am able to see that the dependencies have been successfully built via the logs. However, the require is not defined error still persists.

更新4:即使存在所有软件包和依赖项,从CLI尝试npm安装也无法正常工作

Update 4: Trying npm install from my CLI doesn't work as well even though all packages and dependencies are present

更新5:运行 cf restage 或通过 cacheDirectories 效果不佳

Update 5: Running cf restage or configuring cache via cacheDirectories does not work as well

打开了有关部署的相关问题此处

Opened a related question regarding deployment here

推荐答案

发现我的困惑是由于我没有意识到除非通过Browserify之类的工具,否则无法在客户端使用 require()

Found out my confusion was caused due to me not realizing that require() cannot be used on the client side unless via tools such as Browserify.

这篇关于节点程序包对IBM Cloud Foundry的依赖关系-需求/模块未定义(程序包未加载)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆