Playground Cannot find module 'babylonjs'. Did you mean to set the 'moduleResolution' option to 'node' or add aliases to the 'paths' option?

Hi, I’m trying to create a reproducible bug using the playground.

When I paste in my typescript code, I’m importing types and classes using the import statement.

But the Playground is giving me an error:

Playground Cannot find module 'babylonjs'. Did you mean to set the 'moduleResolution' option to 'node' or add aliases to the 'paths' option?

How can I fix it?

For example:

import type { Behavior, Nullable, Observer, PointerInfo } from 'babylonjs'
import { AbstractMesh, Scene, Observable, Vector3 } from 'babylonjs'

Thank you!

You do not need to import anything in the playground.

BABYLON namespace is available globally to be used as you can see in the default ts playground.

Hi Sebavan, thanks for replying. I saw that in the code example, but it’s not how I’d expect any real-world typescript project to be structured.

I looked through the UI and didn’t see any switches or config options. Is there something I missed?

I remember doing imports on sites like HackerRank and other browser runtimes.

Is there a reason imports can’t be done?

A simple workaround could be to transpile

import { Scene } from 'babylonjs'

to

const { Scene } = BABYLON

Which is what I’d do by hand if imports didn’t work.

Thanks!

This is mostly related to the way the playground has been set. cc @RaananW

In a future version of the playground we are planning on allowing imports, but this won’t happen in the near future. For the time being, the playground supports the BABYLON namespace with all of its different namespaces (GUI, Inspector and so on).

Got it, thank you!

1 Like