Skip to content

Instantly share code, notes, and snippets.

@wires
Last active August 15, 2019 11:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wires/0ac35393ad94aab78c0067088c848319 to your computer and use it in GitHub Desktop.
Save wires/0ac35393ad94aab78c0067088c848319 to your computer and use it in GitHub Desktop.
package.json

Cannot use citation-js with the Parcel bundler it seems because citation-js defines it's own version of require

To demonstrate the problem, run npm start

You then see this error in the console

Uncaught TypeError: Cannot read property 'system_id' of undefined
    at engines.js:15
    at CSL.Blob.<anonymous> (engines.js:34)
    at CSL.Output.Queue.string (citeproc_commonjs.js:5262)
    at CSL.Output.Queue.string (citeproc_commonjs.js:5159)
    at CSL.Engine.CSL.getBibliographyEntries (citeproc_commonjs.js:8528)
    at CSL.Engine.makeBibliography (citeproc_commonjs.js:8239)
    at bibliography (bibliography.js:42)
    at format (output.js:30)
    at Cite.format (get.js:18)
    at Object.parcelRequire.index.js.citation-js (index.js:5)

If instead, you just load the index.html file without bundling, the library works

<html>
<body>
<!-- remove this line to use with parcel -->
<script src="https://cdn.jsdelivr.net/npm/citation-js"></script>
<script src="index.js"></script>
</body>
</html>
const Cite = require('citation-js')
let example = new Cite('Q21972834')
let output = example.format('bibliography', {
format: 'text',
template: 'apa',
lang: 'en-US'
})
console.log(output)
{
"name": "bla",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "parcel serve index.html"
},
"browserslist": [
"last 2 Chrome versions"
],
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"parcel": "^1.12.3",
"parcel-bundler": "^1.12.3"
},
"dependencies": {
"citation-js": "^0.4.8"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment