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

Uncaught StandardMaterial needs to be imported before as it contains a side-effect required by your code #14034

Closed
8Observer8 opened this issue Jul 10, 2023 · 1 comment

Comments

@8Observer8
Copy link

I created a minimal example demonstrating the problem. Error message: Uncaught StandardMaterial needs to be imported before as it contains a side-effect required by your code

<!DOCTYPE html>

<html>

<head>
    <meta charset="utf-8">
    <title>Example</title>
</head>

<body>
    <canvas id="renderCanvas" width="400" height="400"></canvas>

    <!-- Since import maps are not yet supported by all browsers, its is
        necessary to add the polyfill es-module-shims.js -->
    <script async src="https://unpkg.com/es-module-shims@1.7.3/dist/es-module-shims.js"></script>

    <script type="importmap">
        {
            "imports": {
                "@babylonjs/core": "https://unpkg.com/@babylonjs/core@6.11.1",
                "@babylonjs/core/": "https://unpkg.com/@babylonjs/core@6.11.1/"
            }
        }
    </script>

    <script type="module">
        import { ArcRotateCamera } from "@babylonjs/core/Cameras/arcRotateCamera.js";
        import { Engine } from "@babylonjs/core/Engines/engine.js";
        import { MeshBuilder } from "@babylonjs/core/Meshes/meshBuilder.js";
        import { Scene } from "@babylonjs/core/scene.js";
        import { Vector3 } from "@babylonjs/core/Maths/math.vector.js";

        const canvas = document.getElementById("renderCanvas");
        const engine = new Engine(canvas, true);

        const scene = new Scene(engine);
        const sphere = MeshBuilder.CreateSphere("Sphere", { diameter: 2, segments: 32 }, scene);

        const camera = new ArcRotateCamera("Camera", -Math.PI / 2, Math.PI / 2.5, 15, new Vector3(0, 0, 0), scene);
        camera.setTarget(Vector3.Zero());
        camera.attachControl(canvas, true);

        engine.runRenderLoop(() => {
            scene.render();
        });
    </script>
</body>

</html>
@8Observer8
Copy link
Author

I'm sorry. That's my fault. I had to import:

import { StandardMaterial } from "@babylonjs/core/Materials/standardMaterial.js";
<!DOCTYPE html>

<html>

<head>
    <meta charset="utf-8">
    <title>Example</title>
</head>

<body>
    <ul>
        <li><a href="https://github.com/BabylonJS/Babylon.js/issues/14034">Issue</a>
        <li><a href="https://forum.babylonjs.com/t/problems-loading-babylon-via-es-modules/2031/39?u=8observer8">Topic</a>
    </ul>
    <br>
    <br>
    <canvas id="renderCanvas" width="400" height="400"></canvas>

    <!-- Since import maps are not yet supported by all browsers, its is
        necessary to add the polyfill es-module-shims.js -->
    <script async src="https://unpkg.com/es-module-shims@1.7.3/dist/es-module-shims.js"></script>

    <script type="importmap">
        {
            "imports": {
                "@babylonjs/core": "https://unpkg.com/@babylonjs/core@6.11.1",
                "@babylonjs/core/": "https://unpkg.com/@babylonjs/core@6.11.1/"
            }
        }
    </script>

    <script type="module">
        import { ArcRotateCamera } from "@babylonjs/core/Cameras/arcRotateCamera.js";
        import { Engine } from "@babylonjs/core/Engines/engine.js";
        import { MeshBuilder } from "@babylonjs/core/Meshes/meshBuilder.js";
        import { Scene } from "@babylonjs/core/scene.js";
        import { StandardMaterial } from "@babylonjs/core/Materials/standardMaterial.js";
        import { Vector3 } from "@babylonjs/core/Maths/math.vector.js";

        const canvas = document.getElementById("renderCanvas");
        const engine = new Engine(canvas, true);

        const scene = new Scene(engine);
        const sphere = MeshBuilder.CreateSphere("Sphere", { diameter: 2, segments: 32 }, scene);

        const camera = new ArcRotateCamera("Camera", -Math.PI / 2, Math.PI / 2.5, 15, new Vector3(0, 0, 0), scene);
        camera.setTarget(Vector3.Zero());
        camera.attachControl(canvas, true);

        engine.runRenderLoop(() => {
            scene.render();
        });
    </script>
</body>

</html>

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

No branches or pull requests

1 participant