问题描述
所以我最近在C9上使用Node.js并在javascript文件中遇到了这个问题:
So I've been working with Node.js on C9 recently and ran into this problem in a javascript file:
jsdom.env("", function(err, window) {
TypeError: jsdom.env is not a function
这是我的代码:
var jsdom = require('jsdom');
var $;
jsdom.env("", function(err, window) {
console.log("what");
if (err) {
console.error(err);
return;
}
$ = require("jquery")(window);
$.ajax(settings).done(function (response) {
console.log(response);
});
});
我更新了所有的依赖项以及Node本身,但仍然遇到了这个问题。有人知道发生了什么吗?
I updated all my dependencies as well as Node itself but still get this problem. Does anyone know what's up?
推荐答案
我遇到了同样的问题。在整个网络上都在寻找解决方案。事实证明,自从v10以来,jsdom已经更新了一些功能。所以,我想在这里使用jQuery e Node.js快递应用程序的结束,并且必须如下所示:
I was facing the same issue. Was looking for the solution all over the web. It turned out that jsdom has updated some of their features since v10. So, I wanted to use jQuery in the Node.js end of an express app and had to do it like below:
var jsdom = require('jsdom');
const { JSDOM } = jsdom;
const { window } = new JSDOM();
const { document } = (new JSDOM('')).window;
global.document = document;
var $ = jQuery = require('jquery')(window);
.env()已弃用。希望这可以帮助您或任何遇到过这类问题的人。
.env() is deprecated since v10. Hope this helps you or anyone who has been facing these types of issues.
这篇关于jsdom.env没有在node.js C9上工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!