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

Error module stream in ESM build #539

Open
Nisgrak opened this issue Sep 9, 2021 · 11 comments
Open

Error module stream in ESM build #539

Nisgrak opened this issue Sep 9, 2021 · 11 comments

Comments

@Nisgrak
Copy link

Nisgrak commented Sep 9, 2021

Hi!

I'm using this lib in 5.0.6 version with Vite (using the ESM build) and have an error when load the Parser:

browser-external:stream:3 Uncaught Error: Module "stream" has been externalized for browser compatibility and cannot be accessed in client code.
    at Object.get (browser-external:stream:3)
    at json2csv.esm.js:1870

I'm not using the Streaming API, only the synchronous so don't know if it's possible to disabled.

Thanks!

@knownasilya
Copy link
Collaborator

Maybe you can set this option in vite? https://vitejs.dev/config/#optimizedeps-exclude

Or the rollup options here https://vitejs.dev/config/#build-rollupoptions

@Nisgrak
Copy link
Author

Nisgrak commented Sep 10, 2021

I'm trying with this, but happend the same error

optimizeDeps: {
    exclude: ["stream"]
  },

@juliolmuller
Copy link

Any disclosure for that? I'm facing the same issue.

@knownasilya
Copy link
Collaborator

Can you reproduce the issue and upload it as a repo for us to look at?

@filipw01
Copy link

I found a temporary workaround using umd instead

import { parse } from 'json2csv/dist/json2csv.umd'

@oschwede
Copy link

Using a resolve.alias configuration of { "json2csv": "json2csv/dist/json2csv.umd.js" } works as well and does not break the TypeScript definitions.

@juanjoDiaz
Copy link
Collaborator

The problem happens when packaging the library for frontend since it uses some Node libraries. Like the stream library.

In v6 this, will be changed to minimize the node-specific parts and we should reconsider how we expose the different APIs to clearly separate node APIs from standard JS APIs

@daxiaraoming
Copy link

I found a temporary workaround using umd instead

import { parse } from 'json2csv/dist/json2csv.umd'

works for me

@juanjoDiaz
Copy link
Collaborator

Another solution could be to import directly the module that you want to use.
Something like

import parser from 'json2csv/JSON2CSVParser'

Closing since a workaround has been given.

kaiwerther added a commit to Infineon/infineon-vue-datatable that referenced this issue Sep 12, 2022
@juanjoDiaz
Copy link
Collaborator

took long enough....

v6, which has moved to a new repo and broken down into smaller packages is in esm.

Full docs here: https://juanjodiaz.github.io/json2csv/

@TheJaredWilcurt
Copy link

Still same issue with vite and json2csv@v6 (latest). But the UMD workaround still works.

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

8 participants