question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Incompatible with ES6 Modules

See original GitHub issue

I’m unable to load Lunr.js in an ES6 module. I know Lunr isn’t packaged up in an ES6 module, but imported scripts will still cause side effects and the window.lunr global can be used within an ES6 module [stack overflow] [codepen example]:

import "https://unpkg.com/lunr/lunr.js"

var documents = [{ 
  "name": "Lunr",
  "text": "Like Solr, but much smaller, and not as bright."
}, {
  "name": "React",
  "text": "A JavaScript library for building user interfaces."
}, {
  "name": "Lodash",
  "text": "A modern JavaScript utility library delivering modularity, performance & extras."
}]

const lunr = window.lunr

var idx = lunr(function () {
  this.ref('name')
  this.field('text')

  documents.forEach(function (doc) {
    this.add(doc)
  }, this)
})

console.log(idx.search("bright"))

This results in an error: Uncaught TypeError: Cannot set property 'lunr' of undefined. on line 3461 root.lunr = factory()

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:1
  • Comments:16 (3 by maintainers)

github_iconTop GitHub Comments

8reactions
GrosSacASaccommented, Dec 6, 2019

ping @olivernn consider adding contributors to the repo so we don’t have to wait

1reaction
indo-dev-0commented, Jul 28, 2019

I just used a temp file, you can see the results here: https://github.com/indo-dev-0/lunr.js

Read more comments on GitHub >

github_iconTop Results From Across the Web

Grunt and ES6 modules in node - incompatible without ...
So, I'm dabbling a bit with Typescript and Grunt at the moment to see if it's worth it for me. The thing is:...
Read more >
Truffle incompatible with ESMs (ES5 / ES6 modules with " ...
is it possible to execute truffle commands inside a folder in "ESM mode", i.e. package.json contains "type": "module", uses import instead of ...
Read more >
JavaScript modules via script tag | Can I use... Support ...
Loading JavaScript module scripts (aka ES6 modules) using <script type="module"> Includes support for the nomodule attribute.
Read more >
JavaScript modules - MDN Web Docs
This guide gives you all you need to get started with JavaScript module syntax. A background on modules. JavaScript programs started off pretty ......
Read more >
16. Modules
ES6 is the first time that JavaScript has built-in modules. ES6 modules are ... The two most important (and unfortunately incompatible) standards are:....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found