Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: console.Console is not a constructor #151

Closed
jbonevich opened this issue May 30, 2018 · 4 comments
Closed

TypeError: console.Console is not a constructor #151

jbonevich opened this issue May 30, 2018 · 4 comments
Assignees
Labels
bug Something isn't working right

Comments

@jbonevich
Copy link

jbonevich commented May 30, 2018

Not sure if this is Stupid User Error, a bug in citation-js, or a bug in one of its dependencies, but when I use citation-js in a React app from the browser, I get the error 'TypeError: console.Console is not a constructor' at node_modules/citation-js/lib/logger.js:10.

My code:

import React, {Component} from "react";
import Cite from 'citation-js';

class Source extends Component {
  render() {
    const citation = '@book{fake2018\n author="Me Johnson"\n title="Big Book of Bytes"\n publisher="Harper"\n year=2018\n}';
    const data = new Cite(citation);
    return (
      <div>{data.format('citation-chicago')}</div>
    )
  }
}

(Note: I do not know if citation-chicago is an actual format, but appear to not get that far in processing anyway).
Anything I am missing?

@larsgw larsgw added the bug Something isn't working right label Jun 1, 2018
@larsgw larsgw self-assigned this Jun 1, 2018
@larsgw
Copy link
Owner

larsgw commented Jun 1, 2018

I'm using a Node-only API there, but there's a browser-fallback too, which doesn't seem to get used for some reason. How do you run the code in the browser? Browserify should pick it up, but webpack might not...


As for citation-chicago, no, that won't work either. The equivalent of that in the new API (Cite#format) would be

data.format('bibliography', {template: 'chicago'})

Apart from that, the chicago template isn't added by default, as only apa, vancouver and harvard1 are. You'd have add it yourself:

Cite.CSL.register.addTemplate('chicago', xml)

The xml is available here: https://github.com/citation-style-language/styles

@jbonevich
Copy link
Author

jbonevich commented Jun 1, 2018

I am running a React app via npm with react-scripts, which uses webpack. I installed citation-js via npm, but did nothing else special (I do note the "Browser releases" in the instructions, but am unclear if that applies in this situation).

And thanks for the info on chicago style!

@larsgw
Copy link
Owner

larsgw commented Jun 2, 2018

No, if you want to use webpack, those instructions don't really apply. I can fix this particular issue (sometime soon, not right now), but webpack might have other problems, for example with babel config. I'll have to see about that later. Perhaps distributing a browser file, with or without dependencies, on npm would work.

larsgw added a commit that referenced this issue Jun 3, 2018
Remove the use of the 'browser' field in
package.json for files about logging, as webpack
doesn't support it in the same way that
browserify does.

Fix #151
@larsgw
Copy link
Owner

larsgw commented Jun 3, 2018

I published v0.4.0-5, which should fix this particular error, but you might still get other ones – I'm not entirely familiar with webpack and how it interacts with (browserify-based) config. If you do get errors, please do let me know.

@larsgw larsgw closed this as completed in 8e45e9d Jun 3, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working right
Projects
None yet
Development

No branches or pull requests

2 participants