我想解析ini文件 这是我的 html 代码:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script type="module" src="parseINIFile.js"></script>
</head>
<body>
</body>
</html>
和 parseINIFile.js :
import {parse} from "ini";
console.log(parse("name=name\nage=age"));
它给出了 2 个错误:
1)
Access to script at 'file:///C:/Users/User/Documents/JS/parseINIFile.js' from origin 'null' has been blocked by CORS policy: Cross origin requests are only supported for protocol schemes: http, data, isolated-app, chrome-extension, chrome, https, chrome-untrusted.
2)Failed to load resource: net::ERR_FAILED
相反,它应该给我对象{name:name,age:age}。
我尝试使用 require:
const {parse} = require("ini");
console.log(parse("name=name\nage=age"));
但它没有改变。
对不起英语。
似乎是 CORS 错误
查看这篇文章以获取更多解释: https://stackoverflow.com/a/41965272/10906594