【发布时间】:2016-05-22 12:11:21
【问题描述】:
为什么我不能运行node -e ".load ./script.js"?
$ node -e '.load ./script.js'
[eval]:1
.load
^
SyntaxError: Unexpected token .
at Object.exports.runInThisContext (vm.js:53:16)
at Object.<anonymous> ([eval]-wrapper:6:22)
at Module._compile (module.js:410:26)
at node.js:578:27
at nextTickCallbackWith0Args (node.js:419:9)
at process._tickCallback (node.js:348:13)
我尝试使用\ 转义.,但这也不起作用。
【问题讨论】:
-
这不是有效的 JavaScript 代码,您希望发生什么?你的意思是
require('./script.js')? -
在节点交互模式下有效。 stackoverflow.com/a/15387586/903980
-
不,它在 REPL 中有效,这与交互模式有很大不同。
-
$ node --interactive,> .load ./script.js工作正常。
标签: node.js