问题描述
我想在 nodeJS 服务器中使用 processingJS 作为 npm 包,以便在 MS Azure 上进行部署.我正在使用 VS15.我在引用它时遇到问题:
I'd like to use processingJS as an npm package in a nodeJS server for deployment on MS Azure. I'm using VS15. I'm having trouble referencing it:
var pjs = require('processing-js');
var http = require('http'),
fs = require('fs');
var port = process.env.port || 1337;
我的代码的第一行抛出
ReferenceError: navigator is not defined
我所做的研究让我相信 navigator 是与浏览器相关的一些属性,但我无法找到更多信息.
The research I've done leads me to believe that navigator is some property related to the browser but I'm having trouble finding more information.
我已经查看了这些资源,但无法提出解决方案:
I have looked at these resources but wasn't able to come up with a solution:
Require('jquery-ui') innode-webkit 产生导航器未找到错误
https://github.com/tobie/ua-parser/issues/440
http://fredkschott.com/post/2014/06/require-and-the-module-system/
我希望能够将处理预编译为 javascript.
I'd like to be able to precompile processing into javascript.
提前致谢.
推荐答案
navigator
是主机环境在桌面浏览器中可用的对象.(很像 DOM)——javascript 语言没有定义 navigator
对象,所以 V8(底层引擎)没有提供它,因为 node 不是浏览器,它没有也可以实现 navigator
对象.
navigator
is an object available in a desktop browser by the host environment. (Much like the DOM) -- the javascript language doesn't define the navigator
object so V8 (the underlying engine) doesn't provide it and since node isn't a browser, it doesn't implement the navigator
object either.
处理被设计为仅在浏览器中使用——要么您需要在节点中为它提供一个垫片环境,要么在浏览器中使用它(无论是否无头)
Processing is designed to be used solely in the browser -- either you're going to need to provide a shimmed environment for it in node, or use it in the browser (either headless or not)
这篇关于require(processing-js) 抛出参考错误:未找到导航器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!