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

pc.app is null in ESM build #6138

Open
marklundin opened this issue Mar 11, 2024 · 4 comments
Open

pc.app is null in ESM build #6138

marklundin opened this issue Mar 11, 2024 · 4 comments
Assignees

Comments

@marklundin
Copy link
Member

marklundin commented Mar 11, 2024

In UMD build app is added to the pc export which provides pc.app

let app = null;

In the ESM build, app is part of the App-Base module scope and is initialised as part of the app startup. This means that

import { app } from 'playcanvas'
// app === null;

However, importing later it will resolve. This seems error prone and inconsistent with expectations with how imports work. Ideally this should be removed, but may be used by users. There needs to be a solution to migrate away from this.

@Maksims
Copy link
Contributor

Maksims commented Mar 11, 2024

Definitely used a lot by users, as it is the most common way to reference apps outside of scripts.

@marklundin
Copy link
Member Author

To clarify, it is actually exported but it's null until the app has been initialised. Updated comment to reflect this

@Maksims
Copy link
Contributor

Maksims commented Mar 11, 2024

Here is one example of a use case:

  1. Some external script wants to subscribe or fire a global event on app: pc.app.fire('someEvent');.
  2. During development in the console it is convenient to do something like: pc.app.root.findByName('Entity') for inspecting entities and so on.

Do these cases still work with ESM?

@marklundin
Copy link
Member Author

It doesn't really change between ES5/ESM. In either situation pc.app is null until it isn't, so pc.app.fire('someEvent') works once app is available. It's more a question of whether it should be exported

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: No status
Development

No branches or pull requests

2 participants