Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/435.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 找不到模块';xhr2&x27;_Javascript_Json - Fatal编程技术网

Javascript 找不到模块';xhr2&x27;

Javascript 找不到模块';xhr2&x27;,javascript,json,Javascript,Json,PFB片段: let XMLHttpRequest = require('xhr2'); let xhr = new XMLHttpRequest(); xhr.open('GET', 'data.json', true); xhr.send(); 错误: 内部/modules/cjs/loader.js:969 犯错误; ^ 错误:找不到模块“xhr2” 我已安装:npm安装xmlhttprequest 但是我仍然会遇到这个错误。好吧,它告诉你没有安装'xhr2',所以不妨试试npm I x

PFB片段:

let XMLHttpRequest = require('xhr2');
let xhr = new XMLHttpRequest();
xhr.open('GET', 'data.json', true);
xhr.send();
错误: 内部/modules/cjs/loader.js:969 犯错误; ^

错误:找不到模块“xhr2”

我已安装:npm安装xmlhttprequest
但是我仍然会遇到这个错误。

好吧,它告诉你没有安装'xhr2',所以不妨试试
npm I xhr2


sry我会发表评论,但没有足够的声誉或其他什么

xmlhttprequest
有什么关系?如果要使用
xhr2
,为什么要安装
xmlhttprequest
?您是否尝试过
npm i xhr2
?我这样做了,但它给了我另一个错误:抛出新的NetworkError(
不支持的协议${this.\u url.protocol}
);您可以安装
npm i xmlhttprequest
并将其与
let xmlhttprequest=require('xmlhttprequest')一起使用
或安装
npm i xhr2
并将其与
一起使用,让XMLHttpRequest=require('xhr2')“我这样做了,但它给了我另一个错误:
抛出新的NetworkError(不受支持的协议${this.\u url.protocol});
”这是一个新的、不相关的问题。我尝试过,但仍然不起作用。我接着说: