I get this error and Im not exactly sure what else needs to added to make it work, the current render.js file looks as follows:

import Realm from "realm";

and the error i receive when this is run is: Uncaught TypeError: Failed to resolve module specifier "realm". Relative references must start with either "/", "./", or "../".

Any help would be much appreciated thankyou!

I have tired installing both the realm and realm-web to see if there something wrong with the packages but no luck.

1

There are 1 best solutions below

3
Emir Alper Yildiz On

I did some researching. It seems problem is about how you import this package. Problem is not about MongoDB.

Source of the information. I copied from here: Website 1

Your import * as L from 'leaflet'; line is copied as-is into the generated JS file.

When you load that generated JS file with the code below the browser understands the import syntax (thanks to the module type), but there the module specifier needs to be different from your TypeScript project. (Website was talking about typescript.)

<script src="scripts/maps/property-map.js" type="module"></script>

For the first solution, assume your scripts/maps/leaflet.js file is the actual Leaflet library script in UMD form (so that it provides the global L object) (either the source or minified version), then you actually do not need to import it explicitly. In your TypeScript project, you can remove the import line; TS will still know what L is, because it eagerly loads definitions from your node_modules/@types folder: In the browser loading the generated JS file without the import, it knows what L is, because it is previously assigned by Leaflet library as UMD.

Another solution is that you can import as absolute paths which are urls.

import * as L from "https://cdn.jsdelivr.net/npm/[email protected]/dist/leaflet-src.esm.js";

Here is a stack overflow questions asked before (possible duplicates): stack overflow question 1, stack overflow question 2