Javascript &引用;SyntaxError:意外标记';在JSON中的位置0“;当需要使用严格模式的模块时

Javascript &引用;SyntaxError:意外标记';在JSON中的位置0“;当需要使用严格模式的模块时,javascript,json,node.js,module,strict,Javascript,Json,Node.js,Module,Strict,在index.js中我有 'use strict'; const config = require('./config'); 'use strict'; const config = new function() { this.port = 3000; this.redirectUri = "http://localhost:" + this.port + "/auth"; } module.exports = config; 在config.js中我有 'use strict

index.js中
我有

'use strict';

const config = require('./config');
'use strict';

const config = new function() {
  this.port = 3000;
  this.redirectUri = "http://localhost:" + this.port + "/auth";
}

module.exports = config;
config.js中
我有

'use strict';

const config = require('./config');
'use strict';

const config = new function() {
  this.port = 3000;
  this.redirectUri = "http://localhost:" + this.port + "/auth";
}

module.exports = config;
在运行NodeV6.9.5的x64 Windows上,此操作运行良好

但是,在运行node 6.10.2的Raspberry Pi Zero(Raspbian Pixel,ARM v6)上,我得到以下错误:

module.js:590
    throw err;
    ^

SyntaxError: /home/pi/pihas-api/config.json: Unexpected token ' in JSON at position 0
    at Object.parse (native)
    at Object.Module._extensions..json (module.js:587:27)
    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> (/home/pi/pihas-api/index.js:8:16)
    at Module._compile (module.js:570:32)
    at Object.Module._extensions..js (module.js:579:10)
module.js:590
犯错误;
^
SyntaxError:/home/pi/pihas api/config.json:json中的意外标记位于位置0
at Object.parse(本机)
在Object.Module.\u extensions..json(Module.js:587:27)
在Module.load(Module.js:487:32)
在tryModuleLoad时(module.js:446:12)
在Function.Module.\u加载(Module.js:438:3)
at Module.require(Module.js:497:17)
根据需要(内部/module.js:20:19)
反对。(/home/pi/pihas-api/index.js:8:16)
在模块处编译(Module.js:570:32)
在Object.Module.\u extensions..js(Module.js:579:10)

我知道这是因为我在使用
“使用严格”
config.js
中,但我想知道为什么它在Windows上工作,以及是否有办法让它在Pi Zero上也工作。

JSON不是Javascript。不能
“严格使用”在JSON中。

为什么要执行
new function(){…}
?我不想单独导出所有配置
const
,所以我尝试将它们都放在同一个对象中。这不允许我一次性初始化对象,但是,因为在初始化期间我无法访问config对象内的
端口
常量,所以我想我应该使用一个函数,它确实允许我在初始化期间使用
端口
常量,仍然允许我从
index.js
调用
config.port
。糟糕,它实际上是
config.js
。我已编辑该问题。错误消息不一致。SyntaxError堆栈跟踪清楚地显示该文件名为
config.json
。啊,我的错,谢谢!我真不敢相信我没有马上抓住。我的实际
config.js
包含一些敏感数据,因此我没有将其添加到git中。