任何'jspm'命令的JSPM错误:TypeError:无法读取未定义的属性'startsWith'

时间:2016-11-01 10:35:58

标签: node.js npm jspm

通过NPM成功安装JSPM后;

npm install -g jspm

在命令行或'jspm SOMECOMMAND'上运行'jspm'的所有尝试都会导致同样的错误:

C:\some\path> jspm

C:\Users\USERNAME\AppData\Roaming\npm\node_modules\jspm\lib\common.js:108
    if (pjson.startsWith('\uFEFF'))

TypeError: Cannot read property 'startsWith' of undefined
    at exports.readJSONSync (C:\Users\USERNAME\AppData\Roaming\npm\node_modules\jspm\lib\common.js:108:12)
    at Object.<anonymous> (C:\Users\USERNAME\AppData\Roaming\npm\node_modules\jspm\lib\global-config.js:53:18)
    at Module._compile (module.js:570:32)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)
    at Module.require (module.js:497:17)
    at require (internal/module.js:20:19)
    at Object.<anonymous> (C:\Users\USERNAME\AppData\Roaming\npm\node_modules\jspm\lib\registry.js:19:20)

或(另一个例子):

C:\some\path> jspm registry config github

C:\Users\USERNAME\AppData\Roaming\npm\node_modules\jspm\lib\common.js:108
    if (pjson.startsWith('\uFEFF'))

TypeError: Cannot read property 'startsWith' of undefined
    at exports.readJSONSync (C:\Users\USERNAME\AppData\Roaming\npm\node_modules\jspm\lib\common.js:108:12)
    at Object.<anonymous> (C:\Users\USERNAME\AppData\Roaming\npm\node_modules\jspm\lib\global-config.js:53:18)
    at Module._compile (module.js:570:32)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)
    at Module.require (module.js:497:17)
    at require (internal/module.js:20:19)
    at Object.<anonymous> (C:\Users\USERNAME\AppData\Roaming\npm\node_modules\jspm\lib\registry.js:19:20)

这是Node的全新安装。版本:

    C:\some\path> node -v
    v6.9.1

    C:\some\path> npm -v
    3.10.9

编辑:

在“.. \ AppData \ Roaming \ npm \ node_modules \ jspm \ lib \ common.js”中,如果我改变第100行:

var pjson;

var pjson = null;

它改变了错误:

TypeError: Cannot read property 'startsWith' of undefined 

TypeError: Cannot read property 'startsWith' of null 

这是否意味着此try块内的赋值(起始行101)失败并且'pjson'未被赋值?

try {
    pjson = fs.readFileSync(file).toString();
}

1 个答案:

答案 0 :(得分:0)

此问题已在此处解决:

https://github.com/jspm/jspm-cli/issues/2148

问题是我的LOCALAPPDATA环境变量是空的。为了解决这个问题,我将变量设置为AppData文件夹的绝对路径。

即。 C:\ Users \用户名\应用程序数据\本地