我正在 WebStorm 中使用模块化为单页 Web 应用程序创建一个应用程序。我使用带有 & 符号框架的 Node 并组装 browserify 和 watchify。
当我尝试调试我的 app.js 时,出现此错误:-
/usr/local/bin/node --debug-brk=55834 --nolazy app.js
Debugger listening on port 55834
/Users/tori/WebstormProjects/JSProject2_7March/node_modules/ampersand- view/node_modules/events-mixin/node_modules/component-event/index.js:1
tion (exports, require, module, __filename, __dirname) { var bind = window.add
^
ReferenceError: window is not defined
at Object.<anonymous> (/Users/tori/WebstormProjects/JSProject2_7March/node_modules/ampersand-view/node_modules/events-mixin/node_modules/component-event/index.js:1:74)
at Module._compile (module.js:460:26)
at Object.Module._extensions..js (module.js:478:10)
at Module.load (module.js:355:32)
at Function.Module._load (module.js:310:12)
at Module.require (module.js:365:17)
at require (module.js:384:17)
at Object.<anonymous> (/Users/tori/WebstormProjects/JSProject2_7March/node_modules/ampersand-view/node_modules/events-mixin/index.js:6:14)
at Module._compile (module.js:460:26)
at Object.Module._extensions..js (module.js:478:10)
Process finished with exit code 1
谁能解释一下这个错误的含义吗?
最佳答案
您正在使用 Node.js 运行 javascript。但“window”不能在 Node.js 执行的服务器端脚本中使用。它仅在客户端 javascript 中定义,即通过渲染的 HTML 中的标签在浏览器中运行时,而不是在服务器上运行的 Javascript API 引擎中定义。请将您的 app.js 包含在 HTML 文件中(通过 <script src="path/to/app.js">
标记),然后使用 .html 文件右键菜单中的“调试”来调试您的 HTML
关于javascript - WebStorm/usr/local/bin/node --debug-brk=55834 --nolazy app.js,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29124245/