How to import for latest npm modules?

npm i @babylonjs/core@5.0.0-rc.11

import { ActionManager } from "@babylonjs/core/Actions/actionManager.js";
SyntaxError: Named export 'ActionManager' not found. The requested module '@babylonjs/core/Actions/actionManager.js' is a CommonJS module, which may not support all module.exports as named exports.
CommonJS modules can always be imported via the default export, for example using:

import pkg from '@babylonjs/core/Actions/actionManager.js';
const { ActionManager } = pkg;

    at ModuleJob._instantiate (node:internal/modules/esm/module_job:124:21)
    at async (node:internal/modules/esm/module_job:181:5)
    at async Promise.all (index 0)
    at async ESMLoader.import (node:internal/modules/esm/loader:281:24)
    at async loadESM (node:internal/process/esm_loader:88:5)
    at async handleMainPromise (node:internal/modules/run_main:65:12)
[nodemon] app crashed - waiting for file changes before starting...

My import statement is import { ActionManager } from "@babylonjs/core/Actions/actionManager.js"; and it works for @babylonjs/core@5.0.0-beta.12. Are typed imports no longer in fashion ?

This is likely with your build/packaging setup. Perhaps you installed the UMD version by some point by mistake? Perhaps try deleting your /node_modules and rerunning npm i? Or perhaps you are pulling in the UMD (CDN) version at at some point earlier in the page load?

This is a running environment on codesandbox that is using 5.0.0-rc.11 and shows there are no issues importing ActionManager:

1 Like

I think it might be cause some of the properties of the package.json are not present anymore like:

    "esnext": "index.js",
    "type": "module"

cc @RaananW as some others like license repository and such might be also good to add back.

PS: I am totally not sure :slight_smile:


@kaliatech First off, major thanks for taking time out on a wkend to repro ! Appreciate the effort. Using a barebones project with vite on my local machine, there were no issues. I was able to use rc.11 as well. I figured my own project might have a corrupt file somewhere so I removed my node_modules folder and npm i. No dice. When I manually rollbacked to beta.12, build worked fine.

@sebavan I’ve compared beta.12 and rc.11's package.json. Indeed, the difference seems to be in "type": "module". And perusing node’s help, it appears that you are indeed spot on.

Node.js will treat the following as ES modules when passed to node as the initial input, or when referenced by import statements or import() expressions:

Files with an .mjs extension.

Files with a .js extension when the nearest parent package.json file contains a top-level "type" field with a value of "module".

Strings passed in as an argument to --eval, or piped to node via STDIN, with the flag --input-type=module.

I’ve since reverted to beta.12 as I don’t want my development to stall. Any advice going forward would be much appreciated.

rc.12 will be released shortly with some changes, including those 2


Hi @phaselock just checking in, did you have an opportunity to update and check if everything is ok?

1 Like

hi, thanks for the ping. I just updated to 5.3.0 and import statements are working again. I’m getting weird this._scene.beginAnimation is not a function errors but its unrelated to this thread.

Marking this thread as solved, thanks for the heads up ! Cheers ! :slight_smile:

edit: for anyone having beginAnimation with animation ranges using 5.3.0 build, you need
import { Animatable } from "@babylonjs/core/Animations/animatable.js";.
Hope it helps.

1 Like