我已经建立了一个React应用程序,使用 https:/create-react-app.dev。. 当我启动应用程序时,一切都很好 yarn start
的开发模式下。但当我使用 yarn build
当触发一个XML转换时,我得到了这个错误。
classCallCheck.js:3 Uncaught (in promise) TypeError: Cannot call a class as a function
at e.exports (classCallCheck.js:3)
at new n (NodeImpl.ts:93)
at n.<anonymous> (createSuper.js:14)
at new n (DocumentImpl.ts:69)
at Object.t.create_document (CreateAlgorithm.ts:61)
at new n (WindowImpl.ts:28)
at Function.value (WindowImpl.ts:41)
at Object.t.create_window (CreateAlgorithm.ts:47)
at e.get (DOMImpl.ts:68)
at new e (DOMImplementationImpl.ts:27)
我已经找到了引发这个错误的一行。
import { create } from 'xmlbuilder2';
const xmlDoc = create({ version: '1.0', encoding: 'UTF-8', standalone: true }, jsObject);
所以当我的对象转换为XML时就会触发这个错误. 在开发环境中,xmlbuilder2工作得很好。
我正在使用 [email protected]
有谁知道如何解决这个问题?
下面是重现它的简单代码。
import React from 'react';
import logo from './logo.svg';
import './App.css';
import { create } from 'xmlbuilder2';
const testJson =
{
"widget": {
"debug": "on",
"window": {
"title": "Sample Konfabulator Widget",
"name": "main_window",
"width": 500,
"height": 500
},
"image": {
"src": "Images/Sun.png",
"name": "sun1",
"hOffset": 250,
"vOffset": 250,
"alignment": "center"
},
"text": {
"data": "Click Here",
"size": 36,
"style": "bold",
"name": "text1",
"hOffset": 250,
"vOffset": 100,
"alignment": "center",
"onMouseUp": "sun1.opacity = (sun1.opacity / 100) * 90;"
}
}
}
const xmlDoc = create(testJson);
const compl = xmlDoc.end({prettyPrint: true});
console.log(compl);
function App() {
return (
<div className="App">
<header className="App-header">
<img src={logo} className="App-logo" alt="logo" />
<p>
Edit <code>src/App.js</code> and save to reload.
</p>
<a
className="App-link"
href="https://reactjs.org"
target="_blank"
rel="noopener noreferrer"
>
Learn React
</a>
</header>
</div>
);
}
export default App;
node --version
v12.18.0
npm --version
6.14.5
我在MacOS 10.14.6和Windows 10上有同样的问题。
作为一个变通的方法,我使用 xmlbuilder
代替。
通过github联系开发者后 https:/github.comoozcitakxmlbuilder2issues23。 并产生了一个问题,它原来是一个错误。很快就被修复了,并且不再发生在我们的网站上。[email protected]
.