Node.js cfenv 在本地主机上导致 TypeError

标签 node.js ibm-cloud cloud-foundry

在我的 app.js 中,行“var cfenv = require 'cfenv';”原因

path.js:8
    throw new TypeError('Path must be a string. Received ' +
    ^

TypeError: Path must be a string. Received undefined
at assertPath (path.js:8:11)
at Object.posix.join (path.js:479:5)
at getPortsFile (/Users/user1/Dev/src/bluemix/dirt/node_modules/ports/index.js:62:15)
at Object.<anonymous> (/Users/user1/Dev/src/bluemix/dirt/node_modules/ports/index.js:13:29)
at Module._compile (module.js:425:26)
at Object.Module._extensions..js (module.js:432:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:311:12)
at Module.require (module.js:366:17)
at require (module.js:385:17)

模块“cfenv”安装在本地 node_modules 中,并且该应用程序可以在 Bluemix 上运行。

这是 package.json,但版本似乎没有影响它。这只是最近才开始导致错误,但我无法追踪起源......

"dependencies": {
    "express": "4.12.4",
    "cfenv": "1.0.3"
},
"repository": {},
"engines": {
    "node": "0.12.x"
} 

最佳答案

您必须包含您的 cfenv 包,例如使用以下代码:

var cfenv = require ("cfenv");


从您的消息来源我发现您没有使用正确的语法 require('package')

var cfenv = require 'cfenv';

您可以看到圆括号丢失了。

关于Node.js cfenv 在本地主机上导致 TypeError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34028318/

相关文章:

cloud-foundry - 在 Spring 的 application.yml 上获取 VCAP_APPLICATION 的 application_name 值

node.js - 我们如何在 https.agent 中设置 SSL 证书密码?

node.js - 如何在 NodeJS 中编写双向双工流

ibm-cloud - 如何在 html 中加载/配置 IBM Daeja ViewONE?

java - 云类型转换 : update WAR without reverting server. xml

cloud-foundry - 删除与过滤器匹配的所有应用

bash - cp : target is not a directory

javascript - 使用 lodash 检查空对象返回 false

javascript - webpack:在 MacOS 上正常,在 linux 上加载程序错误

java - 蓝色混合 : Java Rest API starter app