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" />
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 works:
this.viewer = new window.Autodesk.Viewing.Private.GuiViewer3D(this.viewerContainer)
this doesn't work:
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;
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>
...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With