简体   繁体   English

Microsoft JScript 运行时错误:代码:800A1391 在运行 node.js 程序时未定义“控制台”

[英]Microsoft JScript runtime error : Code : 800A1391 'console' is undefined while running node.js program

I am new to node.js.我是 node.js 的新手。 I have created a file named myFirst.js after installing node.js in Windows machine.在 Windows 机器上安装 node.js 后,我创建了一个名为 myFirst.js 的文件。 The file looks like following :该文件如下所示:

console.log("Sweet .. Welcome to Node.js"); 

But when I try to navigate to that directory and execute the file it throws an error like the following :但是当我尝试导航到该目录并执行该文件时,它会引发如下错误: 在此处输入图片说明

Even a command like甚至像这样的命令

在此处输入图片说明

is not working.不管用。 What am I missing ?我错过了什么? How would I execute my first node.js code block ?我将如何执行我的第一个 node.js 代码块?

HALAR's helpful answer : HALAR 的有用回答

  • explains that *.js file are by default executed by Microsoft's obsolescent WSH ( Windows Script Host ) JavaScript engine ( JScript ) rather than Node.js ,解释了*.js文件默认由 Microsoft 过时的WSHWindows 脚本主机)JavaScript 引擎( JScript )而不是 Node.js 执行

  • and that passing a Node.js *.js script directly to the node.exe executable ensures its proper execution .并且将 Node.js *.js脚本直接传递给node.exe可执行文件可确保其正确执行

Alternatively, you can reconfigure file-extension associations so as to make *.js files execute with the Node.js engine by default :或者,您可以重新配置文件扩展关联,以便默认情况下使用 Node.js 引擎执行*.js文件

  • Open a PowerShell console window.打开 PowerShell 控制台窗口。

  • Execute the following, which changes the association of the .js extension in the Windows registry (which takes effect for the current user account only, but, conversely, doesn't require elevation):执行以下操作,更改 Windows 注册表中.js扩展名的关联(仅对当前用户帐户生效,但相反,不需要提升):

New-Item -Force HKCU:\SOFTWARE\Classes\NodeJSFile\shell\Open\Command -Value "`"$((Get-Command node.exe).Source)`" `"%1`" %*"
New-Item -Force HKCU:\SOFTWARE\Classes\.js -Value 'NodeJSFile'

From that point on, invoking *.js files directly will execute them with Node.js ( node.exe ).从那时起,直接调用*.js文件将使用 Node.js ( node.exe ) 执行它们。

Note, however, that you'll have to do this on every machine that you want to behave this way.但是请注意,您必须在每台希望以这种方式运行的机器上执行此操作。

You must prefix your execution of the *.Js file with the node executable to add context, as if to say, "open this file with the node scripting engine, rather than the default Microsoft scripting engine, which does not recognize the 'console' object."您必须在 *.Js 文件的执行前加上节点可执行文件以添加上下文,就像在说,“使用节点脚本引擎打开此文件,而不是默认的 Microsoft 脚本引擎,它无法识别‘控制台’目的。”

Therefore, instead of simply providing the name of the .Js file, like so:因此,不要简单地提供 .Js 文件的名称,如下所示:

myFirst.js

Change it to:将其更改为:

node myFirst.js

The name of the *.js file acts as a parameter to the node executable, which is then executed, providing you with your "Sweet.. Welcome to Node.js" statement. *.js 文件的名称充当节点可执行文件的参数,然后执行该文件,为您提供“Sweet.. Welcome to Node.js”语句。

To answer this, first we need to understand that the error is caused because it is being executed by Windows Script Host .要回答这个问题,首先我们需要了解错误是由Windows Script Host执行引起的。

Now, run the code from your cmd promt with the following syntax:现在,使用以下语法从cmd 提示符运行代码:

>node myFirst.js

or或者

>node <application_name>.js

this will allow the Node.js application to open through V8 JavaScript engine (Google's).这将允许 Node.js 应用程序通过V8 JavaScript 引擎(Google 的)打开。

PS: Please reply back if this has helped in resolving your issue else post the problem you are facing after trying this. PS:如果这有助于解决您的问题,请回复,否则请在尝试此操作后发布您面临的问题。

I faced this error when was trying to run NodeJs Script ,I saved the script with name similar to "node" command like我在尝试运行NodeJs 脚本时遇到了这个错误,我用类似于“node”命令的名称保存了脚本

node.js节点.js

and when I tried to run当我试图跑步时

node node.js

throw the error Jscript runtime error抛出错误 Jscript 运行时错误

so I just replace the name with some other like,also delete the script with name node.js所以我只是用其他类似的名称替换名称,同时删除名称为 node.js 的脚本

nodescript.js nodescript.js

then it worked.然后它起作用了。

I have the same problem in windows 8 with my example hello_word.js :我的示例hello_word.js在 Windows 8 中hello_word.js了同样的问题:

  1. So I install the node js 7.7.2 vesion in disk D , because there is question of rights and System sécurity when you install in disk c , so it is more difficult to work in disk c所以我把node js 7.7.2 vesion安装在D盘,因为安装在c盘时存在权限和系统安全问题,所以在c盘工作比较困难
  2. when I finished the install wizard, I lunch "cmd" and then I change my position to the d:/ nodejs by using cd d:/nodejs当我完成了安装向导,我的午餐“CMD”然后我改变我的位置d:/ nodejs使用cd d:/nodejs
  3. then there is two issues:那么有两个问题:

    1. execute the node hello_word.js执行node hello_word.js
    2. or at first execute node , so now you are in the node session, then execute requiere('./hello_word.js')或者首先执行node ,所以现在你在 node 会话中,然后执行requiere('./hello_word.js')

good luck祝你好运

Please see this post What exactly does "/usr/bin/env node" do at the beginning of node files?请参阅这篇文章在节点文件的开头“/usr/bin/env node”究竟做了什么?

You will need to add #!/usr/bin/env node to the beginning of your script.您需要将#!/usr/bin/env node到脚本的开头。 This works even on windows.这甚至适用于 Windows。

Please remove if any node.js file in the program file path.请删除程序文件路径中是否有node.js文件。

In the below directory or folder(file path) node.js file exists.在下面的目录或文件夹(文件路径)中存在node.js文件。

C:/Education/Node/node.js 

Remove node.js删除node.js

Then run in command prompt in file myFirst.js file path然后在文件 myFirst.js 文件路径中的命令提示符下运行

node myFirst.js

不要使用 node js 作为文件名,只需将 node.js 文件名重新命名为其他并尝试

if you still get "'node' is not recognized as an internal or external command, operable program or batch file."如果您仍然收到“'node' 未被识别为内部或外部命令、可运行的程序或批处理文件”。 error after node yourjsfile.js command on Windows在 Windows 上 node yourjsfile.js 命令后出错

type node and enter first then type .load .\\yourjsfile.js and enter again输入 node 并先输入然后输入 .load .\\yourjsfile.js 并再次输入

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何修复 Microsoft JScript 运行时错误“800a1391”未定义 - How to fix Microsoft JScript runtime error '800a1391' is undefined 该错误表明,错误:'console' 未定义,代码:800A1391 和来源:microsoft jscript 运行时错误。 请帮我解决这个问题): - the error shows that, error: 'console' is undefined, code: 800A1391 and , source: microsoft jscript runtime error. please help me in solving this ): 如何解决0x800a1391-IE中的Microsoft JScript运行时错误 - How to resolve 0x800a1391 - Microsoft JScript runtime error in IE 0x800a1391-JavaScript运行时错误:“角度”未定义 - 0x800a1391 - JavaScript runtime error: 'angular' is undefined 0x800a1391-JavaScript运行时错误:&#39;ko&#39;未定义 - 0x800a1391 - JavaScript runtime error: 'ko' is undefined 0x800a1391-JavaScript运行时错误:&#39;bobj&#39;未定义 - 0x800a1391 - JavaScript runtime error: 'bobj' is undefined 0x800a1391-JavaScript运行时错误:&#39;PageMethods&#39;未定义 - 0x800a1391 - JavaScript runtime error: 'PageMethods' is undefined 0x800a1391-JavaScript运行时错误:&#39;Stage&#39;未定义 - 0x800a1391 - JavaScript runtime error: 'Stage' is undefined 0x800a1391-JavaScript运行时错误:&#39;__doPostBack&#39;未定义 - 0x800a1391 - JavaScript runtime error: '__doPostBack' is undefined 0x800a1391 - JavaScript运行时错误:&#39;jQuery&#39;未定义 - 0x800a1391 - JavaScript runtime error: 'jQuery' is undefined
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM