Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PSV error when using plugins that were built from sources #1497

Closed
EVOsparkLP opened this issue Nov 25, 2024 · 7 comments
Closed

PSV error when using plugins that were built from sources #1497

EVOsparkLP opened this issue Nov 25, 2024 · 7 comments
Labels

Comments

@EVOsparkLP
Copy link

Describe the bug

When I install the Photo-Sphere-Viewer and some plugins with npm everything works fine.

But as I need to modify an existing plugin (gyroscope) I try to build the plugin from sources. When this "self-built" plugin is added to the viewer, I receive the following error:
config.ts:216 Uncaught (in promise) PSVError: An undefined value was given for plugin 0.

There are no code modifications in the plugin. I'm just trying to get the build process running.

What I did so far:

  • cloned the Photo-Sphere-Viewer repository

  • npm install

  • npm run build (builds without errors; build is available in dist folder)

  • included this build in my project:

import { Viewer } from '../../Photo-Sphere-Viewer-main/packages/core/dist';
import '../../Photo-Sphere-Viewer-main/packages/core/dist/index.css';
import { GyroscopePlugin } from '../../Photo-Sphere-Viewer-main/packages/gyroscope-plugin/dist';

...

this.viewer = new Viewer({
    container: document.querySelector('#psvContainer'),
    panorama: url,
    plugins: [
        [GyroscopePlugin, {
            moveMode: "smooth",
            absolutePosition: true,
            touchmove: false
        }]
    ],
});
  • npm run build (builds without errors)

I tested the integration also with other plugins which did not work either. So I guess the issue is not specific for the gyroscope plugin.

Maybe this is no real bug, but I am just importing the build files in a wrong way? Can someone who has ever modiefied a plugin, share the steps to get this running? Thanks.

Online demo URL

No response

Photo Sphere Viewer version

5.11.1

Plugins loaded

Gyroscope

OS & browser

Windows, Chrome

Additional context

No response

@EVOsparkLP EVOsparkLP added the bug label Nov 25, 2024
@mistic100
Copy link
Owner

Did you put break points to check what is the actual value of GyroscopePlugin ?

Also try import * as GyroscopePlugin to check the whole JS module.

@EVOsparkLP
Copy link
Author

Thanks for your hint. I put a break point and checked the value of the GyroscopePlugin at the point when the viewer is instantiated together with the plugin. There is no difference between the version imported via npm and the local version.

What I found out:
The issue also persists when the plugin is imported via npm and only the core is built locally. Therefore I tried to use the core from npm and only the plugin built from local files:

import { Viewer } from '@photo-sphere-viewer/core'; // core from npm
import "@photo-sphere-viewer/core/index.css"
import { GyroscopePlugin } from '../../Photo-Sphere-Viewer-main/packages/gyroscope-plugin/dist'; // built from local files

In this case the plugin works fine, as long as I use
npm run dev
If I try to build the sources for production
npm run build
then there is still the same error: Uncaught (in promise) PSVError: An undefined value was given for plugin 0.

BTW, the import with "* as" makes no difference. The error remains the same
import * as GyroscopePlugin from '../../Photo-Sphere-Viewer-main/packages/gyroscope-plugin/dist';

@mistic100
Copy link
Owner

mistic100 commented Nov 25, 2024

for sure your locally built "Photo-Sphere-Viewer-main/packages/gyroscope-plugin/dist" has somewhere an import from "@photo-sphere-viewer/core" which resolves successfully if you also have the package available.

The problem is that this check will never work because you actually have two different AbstractPlugin available
https://github.com/mistic100/Photo-Sphere-Viewer/blob/main/packages/core/src/plugins/AbstractPlugin.ts#L119

The solution : use the imports map as described in the setup guide https://photo-sphere-viewer.js.org/guide/#your-first-viewer
And always use package name when importing stuff, only the imports map will reference the local files.
This way you will have only one core module.

@mistic100
Copy link
Owner

mistic100 commented Nov 25, 2024

<script type="importmap">
    {
        "imports": {
            "three": "https://cdn.jsdelivr.net/npm/three/build/three.module.js",
            "@photo-sphere-viewer/core": "../../Photo-Sphere-Viewer-main/packages/core/dist/index.module.js"
        }
    }
</script>

@mistic100
Copy link
Owner

If you use a bundler you will have to configure it properly to make @photo-sphere-viewer/core always reolve to your local files.

@mistic100
Copy link
Owner

Closing as not an issue with the lib.

@mistic100 mistic100 closed this as not planned Won't fix, can't repro, duplicate, stale Nov 25, 2024
@EVOsparkLP
Copy link
Author

Thanks for your fast support! I got it running.
As I am using vue.js I could not use the suggested way with the importmap.

Therefore I changed the package.json like this:

"@photo-sphere-viewer/core": "^5.11.1",
"@photo-sphere-viewer/gyroscope-plugin": "file:resources/js/Photo-Sphere-Viewer-main/packages/markers-plugin/dist",

Then I could import the modules just like before:

import { Viewer } from '@photo-sphere-viewer/core';
import "@photo-sphere-viewer/core/index.css"
import { GyroscopePlugin } from '@photo-sphere-viewer/gyroscope-plugin';

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants