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

Module not found: Can't resolve 'rdf-canonize-native' during build in RDFLib dependency #567

Open
danielbakas opened this issue Mar 6, 2025 · 5 comments

Comments

@danielbakas
Copy link

Hi!

While building a Next.js project that includes RDFLib ([email protected]), the build fails due to a missing module error in rdf-canonize:

Module not found: Can't resolve 'rdf-canonize-native' in '.../node_modules/.pnpm/[email protected]/node_modules/rdf-canonize/lib'

This error seems to originate from rdf-canonize, which is a dependency of jsonld, which in turn is required by RDFLib.

Steps to Reproduce

  1. Create a Next.js project ([email protected]).
  2. Install [email protected] using pnpm.
  3. Run next build.

Expected Behavior

The build should complete successfully without missing dependencies.

Actual Behavior

  • The build fails with Module not found: Can't resolve 'rdf-canonize-native'.
  • The issue appears in the dependency chain: rdflib → jsonld → rdf-canonize.
  • A separate TypeError: Cannot set properties of undefined (setting 'WordArray') also appears in the logs.

Environment

  • Package Manager: pnpm
  • RDFLib Version: 2.2.37
  • Next.js Version: 15.2.1
  • Node.js Version: 23.9.0

Attempts to solve

  • Add rdf-canonize-native dependency → Failed (different error) at installation

Full Log

next dev

   ▲ Next.js 15.2.1
   - Local:        http://localhost:3000
   - Network:      http://192.168.68.105:3000

 ✓ Starting...
 ✓ Ready in 2.7s
 ○ Compiling / ...
 ⚠ ./node_modules/.pnpm/[email protected]/node_modules/rdf-canonize/lib/index.js
Module not found: Can't resolve 'rdf-canonize-native' in '.../node_modules/.pnpm/[email protected]/node_modules/rdf-canonize/lib'

Import trace for requested module:
./node_modules/.pnpm/[email protected]/node_modules/rdf-canonize/lib/index.js
./node_modules/.pnpm/[email protected]/node_modules/rdf-canonize/index.js
./node_modules/.pnpm/[email protected][email protected]/node_modules/jsonld/lib/jsonld.js
./node_modules/.pnpm/[email protected][email protected]/node_modules/jsonld/lib/index.js
./node_modules/.pnpm/[email protected][email protected]/node_modules/rdflib/esm/jsonldparser.js
./node_modules/.pnpm/[email protected][email protected]/node_modules/rdflib/esm/fetcher.js
./node_modules/.pnpm/[email protected][email protected]/node_modules/rdflib/esm/index.js

Conclusion

Thank you in advance!!!

@davidlehn
Copy link
Member

  • We're no longer actively using or updating https://github.com/digitalbazaar/rdf-canonize-native.
  • The performance of https://github.com/digitalbazaar/rdf-canonize on modern runtimes is fine for our use case.
  • We've also moved forward with spec related updates and other improves in the JS code.
  • I think the plan going forward will be to update rdf-canonize to drop support for rdf-canonize-native entirely.
  • If in the future someone updates rdf-canonize-native to use modern Node.js APIs for the C++ version, or uses Rust, or anything like that, we'll look at performance again. I suspect the switch of which API to use would happen up the stack, like in jsonld or higher, and callers could choose which rdf-canon implementation to use. The current API switching support is too difficult to maintain and use.
  • The current issue is tooling that doesn't know how to deal with the speculative require of this library from rdf-canonize. If you can higher up cause that to do nothing, tooling should work. Something like a package.json browser field flag setting this module to null.
  • Addressing these changes is on a near term todo list, but I can't say when we'll get the new updates out. It will be a rdf-canonize release then a major jsonld release with various updates including using the newest rdf-canonize.

@danielbakas
Copy link
Author

danielbakas commented Mar 8, 2025

Hi @davidlehn! Thank you for such meaningful and prompt reply.

If I understand correctly jsonld.js will be updated and drop rdf-canonize-native to replace it with rdf-canonize

Where I got lost is, do you know what is causing this specific issue stemming from rdflib, passing through jsonld and landing in rdf-canonize-native?

And most importantly, do you have any suggestions for this bug fix?

Thank you!!

@davidlehn
Copy link
Member

If I understand correctly jsonld.js will be updated drop rdf-canonize-native and replace it with rdf-canonize

  • rdf-canonize will drop support for using rdf-canonize-native.
  • jsonld will use the updated rdf-canonize.

Where I got lost is, do you know what is causing this specific issue stemming from rdflib, passing through jsonld and landing in rdf-canonize-native?

  • This line is speculatively trying to use rdf-canonize-native:
    https://github.com/digitalbazaar/rdf-canonize/blob/3f69b8fe068dc6cd6f1f6292468896ad5eb920e2/lib/index.js#L40-L44
  • As the rdf-canonize README mentions, you need to explicitly install rdf-canonize-native and pass proper flags for it to even be used.
  • The tooling you are using is trying staticly process the code and blindly loading that library even though it doesn't exist.
  • The theory was that at runtime the code would simply fail to require and support the library in most cases. That's not an elegant solution and we wouldn't write it like that now. At the time, many many years ago, it seemed like a good idea.

And most importantly, do you have any suggestions for this bug fix?

As I mentioned, you need to make your tooling ignore that require. In webpack or similar you might be able to do something like the following in package.json:

"browser": {
  "rdf-canonize-native": false
}

Your tooling might handle the above too or maybe some other way to override specific packages to something else or nothing.

@danielbakas
Copy link
Author

danielbakas commented Mar 8, 2025

  • rdf-canonize will drop support for using rdf-canonize-native.
  • jsonld will use the updated rdf-canonize.

Awesome! Thanks @davidlehn

  • The tooling you are using is trying staticly process the code and blindly loading that library even though it doesn't exist.

That's right! I'm using Next.js and it may be trying to compile the library, but I don't have the library installed.

As I mentioned, you need to make your tooling ignore that require.

Ok. I will try this and come back to share my insights.

Thank you @davidlehn! Means a lot

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

2 participants