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

ESM support #978

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

ESM support #978

wants to merge 1 commit into from

Conversation

btakita
Copy link

@btakita btakita commented Mar 1, 2023

fixes #977

@btakita
Copy link
Author

btakita commented Mar 1, 2023

This PR does not work in vite browsers builds. I will look into a solution to support browsers as well.

Uncaught TypeError: import_module.createRequire is not a function
    <anonymous> papaparse.mjs:2

@btakita btakita force-pushed the issues/977 branch 2 times, most recently from f802e37 to 12d09d5 Compare March 1, 2023 20:09
@btakita
Copy link
Author

btakita commented Mar 1, 2023

With the latest force push, I added the esm directory, which supports esm + browser & esm + module exports, using esm/package.json. ESM & vite browser builds are now supported.

{
	"main": "./index.mjs",
	"browser": "./index.browser.mjs"
}

"browser" takes precedence over "main" & "module" takes precedence over "browser", which is why I'm using "main" & "browser". I have tested this in my astro.js/vite browser & server side builds.

@btakita
Copy link
Author

btakita commented Mar 1, 2023

Here is my astro test page:

---
---
<script>
	import Papa from 'papaparse'
	console.debug('/|debug|1', { Papa, 'globalThis.Papa': globalThis.Papa })
</script>

Which has the console output:

image

@btakita
Copy link
Author

btakita commented Mar 1, 2023

There's a problem with the latest force pushed commit. The vite server side build seems to use the "browser" import, which causes an error:

ReferenceError: require is not defined
    at new DuplexStreamStreamer (/@fs/home/brian/work/portfoliome/censible-core/vendor/PapaParse/papaparse.js:920:16)

Looking into another fix for this...

btakita added a commit to btakita/PapaParse that referenced this pull request Mar 1, 2023
@btakita
Copy link
Author

btakita commented Mar 1, 2023

If vite fixes the issue vitejs/vite#12253, then this PR should work.

In the meantime, I added https://github.com/btakita/PapaParse/tree/vite-plugin-top-level-await, which will work in server side vite builds using the vite-plugin-top-level-await plugin package.

@JonET
Copy link

JonET commented May 30, 2023

Would this allow us to use esm modules in angular-cli as well? Or would more work need to be done for that? Trying to avoid the "optimization bailouts" warning.

Copy link

@jschang19 jschang19 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This modification works for my Nuxt3 project deploying on Cloudflare worker, where I couldn't deploy LLaMAindex since the current version doesn't come with an ESM support. Thx for your contribution!

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

Successfully merging this pull request may close these issues.

ESM support
3 participants