如何解决终端上的Node JS中的“未定义窗口"错误 [英] How to solve 'window is not defined' Error in Node JS on Terminal

查看:588
本文介绍了如何解决终端上的Node JS中的“未定义窗口"错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想包含Angular JS Using require,所以我正在使用以下代码

I want to include angular JS Using require so I am using below code

var ang = require('angular');

但是它显示错误

ReferenceError: window is not defined

我知道未在节点控制台中定义窗口对象,但可以帮助我如何避免此错误?

I Know window object not defined in node console but help me how to avoid this error ?

我希望我的问题可以理解.

I hope my question understandable.

推荐答案

window对象仅在浏览器中定义,而未在Node.js(而是使用process)中定义.

The window object is only defined in the browser, and isn't defined within Node.js (which uses process instead).

出现此错误的原因是,您试图通过浏览器而不是在Node.js环境中要求使用旨在与DOM一起使用的模块(angular.js).

The reason you're getting this error is because you're trying to require a module (angular.js) that was intended to be used with the DOM from a browser, and not within the Node.js environment.

如果要在HTML代码中包含angular,请像使用标记一样将其包含在其他JS文件中一样.

If you want to include angular in your HTML code, include it like you would any other JS file using a tag.

这篇关于如何解决终端上的Node JS中的“未定义窗口"错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆