无法使用伪造查看器编译反应应用程序 - 无法编译 - Autodesk 未定义 un-def [英] can't compile react app with forge viewer - can't compile - Autodesk not defined un-def
问题描述
我们想将我们的一些伪造查看器代码库移动到一个 react-app 中,并且无法弄清楚如何在不附加所有 Autodesk.Viewer 的情况下使用 viewer3d js api.... 在我们的组件中使用 window.*这适用于我们研究过的所有(优秀且广泛的)git 样本.为什么?我们在index.html和react登陆之间加载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>
...
这篇关于无法使用伪造查看器编译反应应用程序 - 无法编译 - Autodesk 未定义 un-def的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!