Running on server throws no-plugin error

Let me paste my reply here:

TypeError: URL.createObjectURL is not a function

What is your node.js version? URL.createObjectURL is only supported since node.js v16.7.0: URL | Node.js v18.7.0 Documentation

1 Like

oops I did not see that part. I didn’t know it was updated. I’m sorry.

Oh dang it’s supported from Node version after 16?

I’m on 12.- right now… hmm… I think highering my node version would cause conflicts with other settings, but let me just try if I can get passed through this URL.createObjectURL error.

Thanks again :slight_smile:

1 Like

I solved my original problem (indexDB thingy) by using importing from @babylon/core and removing babylonjs package.

and that is when I got this problem below

error - node_modules/@babylonjs/core/Misc/fileTools.js (148:17) @ Function.FileTools.LoadImage
TypeError: URL.createObjectURL is not a function

So I started my porject with higher node version (16.7.0) like you recommended, but then I am back to this error again… :frowning:

Babylon.js v4.2.0 - WebGL1
Plugin Availability For GLTF ====> true
-=-on server error-=- ReferenceError: indexedDB is not defined
    at new Database (webpack-internal:///./node_modules/@babylonjs/core/Offline/database.js:40:41)
    at Function._Engines_engine__WEBPACK_IMPORTED_MODULE_3__.Engine.OfflineProviderFactory (webpack-internal:///./node_modules/@babylonjs/core/Offline/database.js:23:12)

Hmm… ah… every problem that I encounter seems to be some project setup I guess

@RaananW I guess the error is from this line: https://github.com/BabylonJS/Babylon.js/blob/master/packages/dev/core/src/Offline/database.ts#L29

When running in node runtime, window is undefined. Therefore this line evaluates to

private _idbFactory = indexedDB

And indexedDB is also not defined in node runtime. Thus @DOEHOONLEE is getting the error.

1 Like

How could I pass fake-indexeddb for Babylon to use? Wouldn’t fake-indexddb or mock-browser solve the problem?

You don’t pass fake-indexeddb to babylon.js. I have not used it. But I guess you need to import indexdedDB

import {
    indexedDB as fakeIndexedDB,
} from "fake-indexeddb";

And then add indexedDB to global object of node runtime.

2 Likes

That’s one way of solving it, yes :blush:

On our end, i can make sure database only initializes if everything required (i.e. URL and indexedDB) is available. This will make the database not be available in certain systems, but that’s acceptable as it is anyhow the case on those systems

3 Likes

About this solution of yours,

Blockquote
Let me paste my reply here:

TypeError: URL.createObjectURL is not a function

What is your node.js version? URL.createObjectURL is only supported since node.js v16.7.0: URL | Node.js v18.7.0 Documentation

is this the case for front-end side as well?

Because I do have another project running Babylon.js on the front-end side only with node version at 12.- and it works fine.

URL is a member of the window object in the browser. Your node version has nothing to do with the browser babylon is running on. When running on the server then the running environment is no longer a browser. It is node, and therefore you need to make sure that the environment has everything you need.
Other environments like Deno or Bun (and future versions of node) do have the needed API, so if you run it on the server you will need to use one of those to make sure it is working as expected.

1 Like
1 Like

@RaananW Did you also fix indededDB?

Babylon.js v5.17.1 - WebGL1
Plugin Availability For GLTF ====> true
-=-on server error-=- ReferenceError: indexedDB is not defined
    at new Database (webpack-internal:///./node_modules/@babylonjs/core/Offline/database.js:39:41)

For this error, I followed the file database.js in node_modules then added

import { indexedDB } from 'fake-indexeddb';

and it still throws the same error :frowning:

I did now - fix missing indexedDB reference in nodejs by RaananW · Pull Request #12814 · BabylonJS/Babylon.js (github.com)

I missed the last indexedDB reference in the line I changed. Should be fine after this merges.

@RaananW oh, wow! That was super fast!

Thank you for the great work.

But would including the

import { indexedDB } from 'fake-indexeddb';

have worked? If I were to add this, should I include it in core/offline/database.js file?

One last thing, is the indexedDB fixed version going to be released soon?

Thank you always for the fast and wonderful work. I really appreciate it :slight_smile:

Usually it is fast for the fix to be released. But if you want to test with fake-indexeddb, can you read the last line in this reply: Running on server throws no-plugin error - #14 by slin

We have weekly minor versions released on thursday morning. So 5.18.0 (if I am not mistaken) will be released in 2 days.

Yes and no! Yes, it would have worked, no, not out of the box :slight_smile:
You will need to set the global namespace’s indexedDB variable to be the imported fake db. Since node’s global object is not called window but global, you would need to set global.indexedDB = indexedDB . If you do that after the import it would have worked.

Oh, YES!!

I added to global for Babylon to use. No more indexedDB error~! Yay~!

I tried adding URL to global like I did for indexedDB, but it didn’t work.

import URL from 'node:url';
// perhaps
global.URL = URL

Am I on a really wrong track?

Is the Deno only way to solve this problem?

Deno is one way, yes :slight_smile:
I am not sure what node:url is, so it might be an implementation issue with this version of URL.

You could also try GitHub - lukeed/url-shim: A 1.5kB browser polyfill for the Node.js `URL` and `URLSearchParams` classes. or GitHub - lifaon74/url-polyfill: Polyfill URL and URLSearchParams to match last ES7 specifications