iTwin / itwinjs-core

Monorepo for iTwin.js Library
https://www.itwinjs.org
MIT License
615 stars 210 forks source link

Model not loading since upgraded from 4.0.* #6763

Closed lijiayi0921 closed 5 months ago

lijiayi0921 commented 5 months ago

Hi,

I upgraded my https://github.com/iTwin packages to latest version (4.6.0 as of today), from @itwin/web-viewer-react@4.0.3 and most of the rest 4.0.2. With the same frontend code, the viewer no longer loads the imodel. The sign-in, as well as the display of all widgets are working. Custom 3D sprites are loaded, only the imodel is missing.

With Firefox i'm getting this error :

Loading Worker from “[http://localhost:3001/viewer/itwin/scripts/parse-imdl-worker.js”]
(http://localhost:3001/viewer/itwin/scripts/parse-imdl-worker.js%E2%80%9D) was blocked because of a disallowed MIME type (“text/html”).

With Chrome this error :

Uncaught SyntaxError: Unexpected token '<'
at handleError (http://localhost:3001/static/js/bundle.js:774837:58)
at http://localhost:3001/static/js/bundle.js:774856:7

Below is my implementation :

 {isLoggedIn || redirectUrl.pathname !== window.location.pathname ?
            (<Viewer
                key={'viewer'}
                iTwinId={props.file?.platformBucket}
                iModelId={props.file?.platformModel!}
                authClient={authClient}
                onIModelAppInit={onIModelAppInit}
                onIModelConnected={onIModelConnected}
                additionalI18nNamespaces={['safe', 'safeTools']}
                uiProviders={[
                    new ViewerNavigationToolsProvider(),
                    new ViewerContentToolsProvider({
                        vertical: {
                            measureGroup: false,
                        },
                    }),
                    new ViewerStatusbarItemsProvider(),
                    new TreeWidgetUiItemsProvider(),
                    new PropertyGridUiItemsProvider(),
                    new MeasureToolsUiItemsProvider(),
                    ...(safeExt?.uiProviders ?? [])
                ]}
                viewCreatorOptions={viewCreatorOptions}
                enablePerformanceMonitors={true}
            />
            ) : null}

Any help will be appreciated ! Thank you

Jiayi

pmconne commented 5 months ago

You need to copy the public assets from @itwin/core-frontend. #6591

lijiayi0921 commented 5 months ago

Thank you @pmconne, but I didn't fully understand. Do you mean to copy all subdirs of @itwin/core-frontend/lib/public (assets, cursor, scripts, ...) into my frontend's public folder ? Just tried and this did'nt solve my problem.

Also what's the reason of copying them? They don't appear in the public folder of the sample app : https://developer.bentley.com/tutorials/web-application-quick-start/

---------------- Edit ------------------- Instead of the public folder, I copied them into public/viewer/itwin based on my error. The models loads again !

Loading Worker from “[http://localhost:3001/viewer/itwin/scripts/parse-imdl-worker.js”]
(http://localhost:3001/viewer/itwin/scripts/parse-imdl-worker.js%E2%80%9D) was blocked because of a disallowed MIME type (“text/html”).

However I still don't understand why this is a necessity. Why it was not required in my previous implementation (4.0.*), and in the sample app ?

pmconne commented 5 months ago

Why it was not required in my previous implementation (4.0.*), and in the sample app ?

The worker script was introduced in 4.2.0.

Presumably the viewer package sets IModelApp.publicPath to "viewer/itwin".

lijiayi0921 commented 5 months ago

Thank you @pmconne for your help & explanation !