Multiple issues when using umd file
See original GitHub issueDisclaimer
🙋♀️ I’m so sorry if I missed something really obvious in JS to remove these errors, but I’m stuck…
With v0.11.0
In my index.html
<script src="https://cdn.jsdelivr.net/npm/meilisearch@0.11.0/dist/bundles/meilisearch.umd.js"></script>
I get in the console:
ReferenceError: require is not defined
<anonyme> https://cdn.jsdelivr.net/npm/meilisearch@0.11.0/dist/bundles/meilisearch.umd.js:5

NB
No error message with:
<script src="https://cdn.jsdelivr.net/npm/meilisearch@0.10.1/dist/bundles/meilisearch.umd.js"></script>
With v0.10.1
(I use it because the v0.11.0
does not work)
I know this version is outdated but maybe there is the same issue in the v0.11.0
too.
In my index.html
file:
<script src="https://cdn.jsdelivr.net/npm/meilisearch@0.11.0/dist/bundles/meilisearch.umd.js"></script>
<script src="./src/app.js"></script>
In .src/app.js
const meiliClient = new Meilisearch({
host: 'http://127.0.0.1:7700',
apiKey: 'masterKey'
})
I get this error in the console:
TypeError: instance is undefinedmeilisearch.umd.js:151:17
MeiliAxiosWrapper https://cdn.jsdelivr.net/npm/meilisearch@0.10.0/dist/bundles/meilisearch.umd.js:151
Meilisearch https://cdn.jsdelivr.net/npm/meilisearch@0.10.0/dist/bundles/meilisearch.umd.js:1098
<anonyme> file:///Users/curquiza/.../src/app.js:69

Plus, you can notice I had to write new Meilisearch
to get it worked (and not new MeiliSearch
) which is really confusing comparing with the Getting Started.
Conclusion
These issues have to be fixed:
- The UMD file should be importable in an HTML (see the first point)
- The UMD file should be usable in a vanilla JS file passed as a script in an HTML file (see the second point)
-
Meilisearch
has to be renamed intoMeiliSearch
in the UMD file - Add tests to check both of the first points if this is possible 😇
Issue Analytics
- State:
- Created 3 years ago
- Comments:13 (13 by maintainers)
Top Results From Across the Web
University of Maryland Box Service Frequently Asked ...
What is Box? Box is a secure, cloud-based storage and collaboration service that allows customers to upload, download, and share multiple file types....
Read more >Can't use UMD file in my page - error is "<name> is not a ...
Answering my own question: There were two problems: I didn't understand that Rollup needs to provide a name for a UMD module; I...
Read more >Output - webpack
webpack will not write output file when file already exists on disk with the same content. ... If multiple modules would result in...
Read more >rollup.js
You can export an array from your config file to build bundles from several unrelated inputs at once, even in watch mode. To...
Read more >Compiling and bundling TypeScript libraries with Webpack
The ideal would be to just have two outputs: commonjs and es modules. The UMD file would serve our needs as commonjs if...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
The reason why it was not importable between two version is because an overwrite of the
umd
bundle with thecjs
bundle was done inrollup.config.js
. This has been fixed.For the next version this is how import will work in the client:
How to import MeiliSearch in v0.11.1 >
Node - CommonJs
Browser - vanilla JS
EcmaScript module - esm
Important, if your bundler uses
browser
as primary entry key, please change it tomodule
. Example in webpack:EcmaScript module Typescript - esm
To make it work with the UMD of the
v0.10.1
you should add the axios CDN like this (order is important):