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

Using jsonld.js in Node-RED (with browserify) #128

Closed
KMax opened this issue Feb 3, 2016 · 4 comments
Closed

Using jsonld.js in Node-RED (with browserify) #128

KMax opened this issue Feb 3, 2016 · 4 comments

Comments

@KMax
Copy link

KMax commented Feb 3, 2016

I use the library as a part of my .js file which is compiled with browserify. The input file for browserify is below and the output file is called bundle.js:

"use strict";

... // other imports via require(...);
global.JSONLD = require('jsonld');

When I import bundle.js in .html file which is a part of any Node-RED plugin and do console.log(JSONLD);, in the console I see an empty object, i.e. Object {}. But if I import the file in a plain HTML outside of Node-RED environment, the library works correctly, i.e. it's imported as a function.

Other libraries which I import in the same way, in example N3.js and axios, work correctly in both cases.

It's just my guess, but probably the issue is in the way the library is exported.

@KMax
Copy link
Author

KMax commented Feb 4, 2016

I found a workaround which unfortunately requires to make small changes in the source code of jsonld.js.

  • comment out lines 8060 - 8079
  • add var factory = wrapper({}); before line 8080
  • comment out lines 8081 - 8091

After these changes, import the library with ... = require('./jsonld.js'); and the code will work in the both cases mentioned earlier.

@elf-pavlik
Copy link
Contributor

I stumbled upon the same issue and patch proposed in previous comment solved it.

@nopnop I remember that you fixed browserify compatibility before in #56, could you imagine taking a look at this issue?

nopnop added a commit to nopnop/jsonld.js that referenced this issue Mar 5, 2018
Using jsonld in a browserify-based build script does not works any more.

This PR update the `browser` key in `package.json` in order force
browserify to use the `dist` version for the browser (generated by
webpack during release process).

This solution provide browserify support without the needs to maintain
complex configuration for both webpack and browserify.
It could be less optimal in term of bundle size (for browserify use a
bundled version of jsonld), but that is better than nothing and the
modern minification tools may resolve this kind of optimization.
@nopnop
Copy link
Contributor

nopnop commented Mar 5, 2018

Hi @elf-pavlik,

Sorry for the late answer (I've seen your notification but I should have been distracted at the time).
I've pushed a PR that is, maybe, an acceptable solution to the browserify support issues.

@dlongley
Copy link
Member

Closing as very old and the landscape has changed -- or this may now potentially duplicate #399 in some way.

botocracy pushed a commit to botocracy/jsonld.js that referenced this issue Jul 9, 2020
Using jsonld in a browserify-based build script does not works any more.

This PR update the `browser` key in `package.json` in order force
browserify to use the `dist` version for the browser (generated by
webpack during release process).

This solution provide browserify support without the needs to maintain
complex configuration for both webpack and browserify.
It could be less optimal in term of bundle size (for browserify use a
bundled version of jsonld), but that is better than nothing and the
modern minification tools may resolve this kind of optimization.
botocracy added a commit to botocracy/jsonld.js that referenced this issue Jul 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants