无法使用Forge Viewer编译React应用-无法编译-Autodesk未定义undef [英] can't compile react app with forge viewer - can't compile - Autodesk not defined un-def
问题描述
我们想将某些伪造查看器代码库移入react-app,并且在不将所有Autodesk.Viewer ....用法附加到带有窗口的组件中的情况下,无法弄清楚如何使用viewer3d js api.*这适用于我们研究过的所有(优秀和广泛)git示例.为什么?我们在到反应登陆之间的index.html文件中加载viewer3d.js文件:
we want to move some of our forge viewer code base into a react-app and can't figure out how to use the viewer3d js api without appending all Autodesk.Viewer.... usages in our components with window.* This works in all the (excellent and extensive) git samples we've studied. why? we load the viewer3d.js file in the index.html between the and the react landing :
<body>
<script src="https://developer.api.autodesk.com/derivativeservice/v2/viewers/viewer3D.js?v=6.0" />
<div id="root" />
我们得到的错误(对于每个使用Autodesk名称空间的实例):
the error we get (for every instance of usage of the Autodesk namespace):
Failed to compile
./src/components/Viewer.js
Line **: 'Autodesk' is not defined no-undef
这有效:
this.viewer = new window.Autodesk.Viewing.Private.GuiViewer3D(this.viewerContainer)
这不起作用:
this.viewer = new Autodesk.Viewing.Private.GuiViewer3D(this.viewerContainer)
推荐答案
As mentioned in this user guide, you need to explicitly read any global variables from window. Put this at the top of the file and it will work:
const Autodesk = window.Autodesk;
并且建议将您的脚本标签拖到应用程序条目html的标头部分,以确保在React发出之前将其加载:
And it's recommended to yank your script tag to the header section of your app's entry html to make sure it gets loaded prior to the React emits:
<!DOCTYPE html>
<html lang="en">
<head>
...
<script src="https://developer.api.autodesk.com/derivativeservice/v2/viewers/viewer3D.js?v=6.0" />
</head>
...
这篇关于无法使用Forge Viewer编译React应用-无法编译-Autodesk未定义undef的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!