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

Unable to import this library in my project!? #361

Open
brandoncollins7 opened this issue Feb 16, 2024 · 7 comments
Open

Unable to import this library in my project!? #361

brandoncollins7 opened this issue Feb 16, 2024 · 7 comments

Comments

@brandoncollins7
Copy link

When I import the latest version import jsondiffpatch from 'jsondiffpatch' I get this error..... super freaking wierd I've never seen anything like this.

require() of ES Module C:\Users\brand\Documents\Projects\atlantic-dawn-monorepo\node_modules\.pnpm\[email protected]\node_modules\jsondiffpatch\lib\index.js from C:\Users\brand\Documents\organization-api\src\api\handlers\handler.js not supported.\nInstead change the require of index.js in C:\Users\brand\Documents\handler.js to a dynamic import() which is available in all CommonJS modules.","ecs":{"version":"1.5.0"},"name":"RethrownError","original":{"code":"ERR_REQUIRE_ESM"}}

@Methuselah96
Copy link
Collaborator

As of v0.6.0 the package is ESM. Take a look at Sindre Sorhus's ESM FAQ and see if that helps.

@howardjones
Copy link

The problem with the FAQ is that it assumes you are a Javascript developer. I had an old-fashioned Flask app (HTML templates rendered on the server by Python) with one page using jsondiffpatch to show changes between config files. It was a couple of includes and 4 lines of code, and very nice! (thanks for that).

Now it seems that I need to learn 15 years of Javascript history to do it? (CommonJS? ESM? Packagers?). The FAQ doesn't mention a browser. I don't have node (except npm to download packages).

Is there a FAQ for the "jQuery crowd"? :-)

@Methuselah96
Copy link
Collaborator

Thanks for the feedback! Is your current setup using a script tag like the Visual Diff example for v0.5.0?

@howardjones
Copy link

Yes, just like that. I switched back to 0.5.0 for now.

@Methuselah96
Copy link
Collaborator

Methuselah96 commented Mar 22, 2024

The Visual Diff example for v0.6.0 should be pretty similar as far as complexity. I need to update it to use ESM.sh instead of skypack.dev because of #360 and then I'll update the Release Notes for v0.6.0 to show an example of how to migrate for that use case.

Let me know if anything sticks out to you about the new way to do it that would not work with your current setup.

@Methuselah96
Copy link
Collaborator

I have updated the example in the README to use ESM.sh and added a note to the v0.6.0 Relase Notes that explains how to upgrade. Let me know if that's helpful.

@howardjones
Copy link

howardjones commented Mar 22, 2024

Is that first URL ('https://cdn.skypack.dev/jsondiffpatch') effectively pointing at a copy of the node_modules jsondiffpatch/lib directory, or some build artifact that needs to be compiled? i.e. can I do this without using a CDN? I can see the formatter files (maybe) in the lib/ directory, but not really clear on what the first import would point to, unless it just adds "index.js" on the end and tries to fetch that. I was going to just confirm with the live demo but I guess that link is broken in a branch.

(in my current setup, I am just adding node_modules/jsondiffpatch/dist as a static mount to the web app)

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

3 participants