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

Browser issue when using vite #123

Open
Sequoia opened this issue Jun 5, 2023 · 3 comments
Open

Browser issue when using vite #123

Sequoia opened this issue Jun 5, 2023 · 3 comments

Comments

@Sequoia
Copy link

Sequoia commented Jun 5, 2023

Hi,

I'm using your library, it's great! There's an issue with some newer browser bundlers like vite, which don't like something about the colors.js library & blow up when I try to use json-diff.

It looks like the calls to colorize (the only link to colors.js) here and here are a passthrough; the CLI module calls colorize directly (not via the index module).

Would you be amenable to this file being split somehow so the main functionality (the diff function) could be imported from the browser without loading colorize?

Perhaps something like:

- lib/core.js
    - export diff
- lib/index.js
    - import diff from core
    - import colorize etc. from colorize
    - function diffString
    - export {diff, colorize, colorizeCallback, diffString } // preserve existing exports

Then a browser consumer like me could

import { diff } from 'json-diff/core'

and bypass the colorize/colors.js import. I think this would work. Does this sound alright if I can get it working?

Sequoia added a commit to Sequoia/json-diff that referenced this issue Jun 12, 2023
@AnthonyRuelle
Copy link

Hello, @andreyvit
I have the same problem and you don't seem to respond to requests
Is it possible to include his changes?

@elcih17
Copy link

elcih17 commented Jul 3, 2023

I managed to get it working in my environment by setting the following configuration.
(Note: I use this with Cypress, so I'm not sure if this will work in other environments.)

import replace from '@rollup/plugin-replace';

export default defineConfig({
  plugins: [
    replace({
      'process.argv': JSON.stringify([]),
      'process.env': JSON.stringify({}),
    }),
  ],
});

yamdan added a commit to zkp-ld/jsonld-proofs that referenced this issue Aug 19, 2023
yamdan added a commit to zkp-ld/zkp-ld-playground that referenced this issue Aug 19, 2023
using patched `json-diff` to avoid the problem with vite
see: andreyvit/json-diff#123
yamdan added a commit to zkp-ld/zkp-ld-playground that referenced this issue Sep 13, 2023
using patched `json-diff` to avoid the problem with vite
see: andreyvit/json-diff#123
@darioackermann
Copy link

I also had to add the following to the replace list (or alternatively, the vite define section) to make Cypress work

{ // ...
    'process.platform': '""',
    'process.stdout': JSON.stringify(false),
    'process.stderr': JSON.stringify(false),
}

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