Closed Ketec closed 2 weeks ago
The library should not contain node.js specific code. The code of svelte-jsoneditor
doesn't contain node:url
, so this may originate in one of the dependencies.
How can I reproduce your issue?
All i did was import and create a new editor in a Angular project (webpack 5).
url and path are nodeJs libraries and are not available in the browser. Older webpack used to bundle these as polyfills by default.
I believe these are the culprits https://github.com/josdejong/svelte-jsoneditor/blob/f2b21c1f75b42209accf96da7949a645c480c845/tools/utils/getAbsolutePath.mjs#L4
Did you import the source code of the project? That indeed contains Node.js files needed to built the library.
If you install the library via npm you'll not get those files.
Same issue here, since ~15h ago. React project, webpack 5.90.0, importing vanilla-jsoneditor v0.23.5 via npm.
Still trying to figure out, any help appreciated.
I installed with npm and imported it into the project. Were they somehow included with the bundle/index? This would cause webpack attempt to compile them.
This is also bringing down our build. Stack:
52.39 @ ../../../../node_modules/fast-uri/index.js 3:12-31
52.39 @ ../../../../node_modules/ajv/dist/runtime/uri.js 3:12-31
52.39 @ ../../../../node_modules/ajv/dist/core.js 22:14-38
52.39 @ ../../../../node_modules/ajv/dist/ajv.js 4:15-32
52.39 @ ../../../../node_modules/vanilla-jsoneditor/index.js 1:15241-15261 1:580480-580482
This is the issue: https://github.com/ajv-validator/ajv/issues/2446
Thanks @jdimmerman , that explains it. So, as a workaround, you can pin down the version of ajv
in your package.json
:
{
"svelte-jsoneditor": "0.23.5",
"ajv": "8.14.0"
}
or:
{
"vanilla-jsoneditor": "0.23.5",
"ajv": "8.14.0"
}
Interestingly, i already have ajv at 8.12.0
So i wonder if it was introduced earlier in a part of ajv i didn't use or import.
The standalone.js version is fine however.
@Ketec maybe there are two issues at play here, with a different cause. Can you share a stacktrace of the error that you get?
@josdejong Any idea how to set this transient dependency for yarn 2.x (berry)? I'm able to set the dep, but yarn is still attempting to install fast-uri even if its not making use of it
Did you define the version numbers as exact in your yarn file? I don't use yarn so I'm afraid you're a bigger expert on it than me.
Ah, no I figured it out. CI was on a different version of yarn with slightly different resolution syntax. Fix for yarn:
"resolutions": {
"ajv@npm:^8.14.0": "npm:8.14.0"
}
Using npm, it is fixed - can also verify by lockfile and also cheking installed folder in node_modules.
Stack trace is being unhelpful as it is entirely from webpack stack.
Should also mention that i am running v18.18.2 - which should be used by webpack during compile time.
Looking through packages, another dependency is jsonrepair that uses node:uri
https://github.com/josdejong/jsonrepair/blob/8d427b6273a9ce7e9cc3859f5dcfbaa790b3851d/bin/cli.js#L5
Looking through packages, another dependency is jsonrepair that uses node:uri
https://github.com/josdejong/jsonrepair/blob/8d427b6273a9ce7e9cc3859f5dcfbaa790b3851d/bin/cli.js#L5
That node:uri
import is there since 2023-11-30, half a year already, and this code is not loaded when loading svelte-jsoneditor
, so I don't think it's related.
Just to be sure: did you update to the latest version of ajv that has the node import fixed again?
@Ketec can you create a minimal example on https://stackblitz.com/ demonstrating your issue? Without a way to reproduce your issue and without any stacktrace I don't know how I can help you.
@Ketec I had a similar issue in an Angular 15 project. Angular packages have a dependency on ajv@8.12.0
.
Explicitly overriding ajv
version for vanilla-jsoneditor
worked for me:
// package.json
"overrides": {
"vanilla-jsoneditor": {
"ajv": "8.14.0"
}
}
This issue should be fixed with ajv@8.16.0
. Please reopen if there are still issues.
The vanilla version (not svelte).
Why is it using nodeJs specific functionality that is not available in browser environments without custom polyfills?