【发布时间】:2019-07-30 02:59:39
【问题描述】:
您好,我在 Azure Web 应用程序中使用 Nodejs 和 reactjs 实现了机器人框架。该代码在 Edge、Chrome 中运行良好,但在 IE 中,我得到带有错误的空白页面。下面是代码。事实上,即使我尝试微软在 github 上的一个示例,它也无法在 IE 中加载。 Here 是示例。
我做了一些研究,发现 reactjs 在 IE 上确实存在一些渲染问题,我们应该在代码中使用 polyfill 包,但我仍然没有运气。
import 'react-app-polyfill/ie11';
declare var require: any
var React = require('react');
var ReactDOM = require('react-dom');
import ReactWebChat, { createDirectLine } from 'botframework-webchat';
import { createStore } from 'botframework-webchat';
import { createStyleSet } from 'botframework-webchat';
import updateIn from 'simple-update-in';
import "babel-polyfill";
import "isomorphic-fetch";
//import 'react-app-polyfill/ie11';
export class BotFrameworkApp extends React.Component {
constructor() {
super();
this.state = {
directLine: null,
styleSet: null,
};
}
const response = await fetch('https://directline.botframework.com/v3/directline/tokens/generate', {
method: 'POST',
headers: {
'Authorization': 'Bearer token',
'Accept': 'application/json',
'Content-Type': 'application/json',
'Access-Control-Request-Headers': 'x-requested-with'
},
body: JSON.stringify({
accessLevel: 'View',
allowSaveAs: 'false',
})
});
const { token } = await response.json();
//already set and now send
this.setState(() => ({
directLine: createDirectLine({ token }),
userName: loginID,
webchatStore: createStore({}, middleware),
styleSet: createStyleSet({
hideUploadButton: true,
bubbleBackground: 'rgba(0, 0, 255, .1)',
bubbleFromUserBackground: 'rgba(0, 255, 0, .1)',
})
}));
}
render() {
const {
state: { data }
} = this
return (
this.state.directLine && this.state.webchatStore ?
<ReactWebChat
className="chat"
directLine={this.state.directLine}
styleSet={this.state.styleSet}
/>
:
<div>Connecting to bot…</div>
);
}
}
ReactDOM.render(<BotFrameworkApp />, document.getElementById('root'));
这是错误,
我的 tsconfig
{
"compilerOptions": {
"noImplicitAny": false,
"module": "commonjs",
"noEmitOnError": true,
"removeComments": false,
"sourceMap": true,
"target": "es6",
"jsx": "react"
},
"exclude": [
"node_modules"
],
"files": [
"app.tsx"
]
}
我的 Webpack-config.js
module.exports = {
devtool: 'source-map',
entry: './app.tsx',
mode: "development",
output: {
filename: "./app-bundle.js"
},
resolve: {
extensions: ['.Webpack.js', '.web.js', '.ts', '.js', '.jsx', '.tsx']
},
module: {
rules: [
{
test: /\.tsx$/,
exclude: /(node_modules|bower_components)/,
use: {
loader: 'ts-loader'
}
}
]
}
}
【问题讨论】:
-
您使用的是哪个版本的IE浏览器版本?据我所知,BotFramework 支持 IE 11+。另外,请详细说明错误信息,我建议你可以参考这个帖子添加react application polyfill,使其在IE浏览器中运行良好。
-
嗨,谢谢你的回复。我使用的是 IE 11.557.17763.0...你能分享到 polyfill 线程的链接吗.....
-
你可以检查this thread和this article。
-
嗨志 - 我尝试了这两种方法仍然没有成功。
-
嗨@mdrichardson-MSFT 是的,根据您的建议,我能够解决这个问题。我确实“使用 polyfills 和像 babel 这样的转译器将代码从 ES6+ 转换为 ES5”
标签: node.js reactjs internet-explorer botframework