Meteor 18.0.2 with 3rd party library (no NPM package)

I came here for help how to add the 3rd party libraries which doesn’t have any npm package to add. I have read some of the topics but no luck in achieving it. I have placed 3rd party lib js files inside client/compatibility or Client/lib/js but getting Object not defined (seems the files are not loaded properly).

Below is my code structure

This is a sample html code snippet which I’m referring to achieve in meteor.

Please help and let me the approach i need to follow.

The special folder client/compatibility doesn’t work if you are using the new entrypoint / lazy-loading semantics, which are turned on by default for new projects since 1.8

Check if your package.json file has a meteor section. If so, try deleting that section
That should pop you back into the older eager-loading + imports structure that a lot of the Meteor guide assumes.

1 Like

Thank you very much for helping this. That works well now.

I have another query, is the scripts can be referred from cdn lets say in case if the 3rd party is releasing patches or bug fix. So that application will be referring the latest one.

If you’re using a script tag with a remote url, then yes it will always use the most up to date version available at that url.
If the url is versioned, then you will need to update the url when new versions are released

Sorry, actually I’m copying the 3rd party js in the client/compatibility folder now.
If i want to use Script tag referring the cdn where it should be defined in the project, is that should be in main or head.html or it should be some other place.

Wherever your <head> is

1 Like

Thanks a lot for your help

@coagmano Need one more advise, I have added some server methods i.e under \server but those methods relied on the client/compatibility folder files. In this case i believe the server methods are loaded first and throwing undefined. Any options to overcome this issue?

The answer to this depends on if / how the library is wrapped.

First of all, Meteor prevents files in a client folder from being loaded on the server, and vice-versa.
To allow it to be loaded on both, it needs to be outside these directories.

That means you lose the magic behaviour of the client/compatibility folder.
Meteor (and most bundlers) wrap each file in an IIFE (Immediately Invoked Function Expression), protecting the global scope from var declarations. Meteor doesn’t do this for the client/compatibility folder, so older libraries that rely on their variables escaping to the global scope can continue to do so.

If the library uses the UMD pattern, or attaches itself to window, then it doesn’t need to be in client/compatibility, and moving it should just work.

If not, you will need to edit it slightly to expose the module correctly

Give moving it a shot and if that doesn’t work, come back with a link to the library and I can take a look at how to expose it

1 Like