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

npm_import failure due to duplicate JSON key #493

Closed
Silic0nS0ldier opened this issue Oct 5, 2022 · 4 comments
Closed

npm_import failure due to duplicate JSON key #493

Silic0nS0ldier opened this issue Oct 5, 2022 · 4 comments
Labels
enhancement New feature or request

Comments

@Silic0nS0ldier
Copy link

Silic0nS0ldier commented Oct 5, 2022

Technically JSON allows duplicate keys, or at least the parser in NodeJS does.

The package @codeceptjs/helper v1.0.2 has duplicate keys in its package.json (specifically scripts), causing Rules JS to fail to parse.

From the answers on https://stackoverflow.com/questions/21832701/does-json-syntax-allow-duplicate-keys-in-an-object originally this was left ambiguous. As of ECMA-262 behaviour of JSON.parse was clarified here, it specifies that the last one wins.

Gross that a package has turned up (most likely be accident) which relies on this. I'll leave it up to maintainers to decide is this is a bug or "ecosystem alignment feature".

Workaround

# WORKSPACE.bazel
...
npm_translate_lock(
    ...
    patch_args = {
        "@codeceptjs/[email protected]": ["-p1"]
    },
    patches = {
        "@codeceptjs/[email protected]": ["//:patches/@[email protected]"]
    },
    ...
)
...
patches/@[email protected]
Generated using pnpm's patch commands.
diff --git a/package.json b/package.json
index 406e3cd21d59b4c77be0a27f5e75dc72a6064262..168861f06bc9cd21579ecfbe035a4fbea30be4d5 100644
--- a/package.json
+++ b/package.json
@@ -7,7 +7,8 @@
     "helper.js"
   ],
   "scripts": {
-    "test": "echo \"Error: no test specified\" && exit 1"
+    "test": "echo \"Error: no test specified\" && exit 1",
+    "docs": "documentation readme helper.js -s API"
   },
   "repository": {
     "type": "git",
@@ -16,9 +17,6 @@
   "keywords": [
     "codeceptjs"
   ],
-  "scripts": {
-    "docs": "documentation readme helper.js -s API"
-  },
   "author": "Michael Bodnarchuk @davert",
   "license": "ISC",
   "bugs": {
// package.json, optional
{
    ...
    "pnpm": {
        "patchedDependencies": {
            "@codeceptjs/[email protected]": "patches/@[email protected]"
        },
    },
    ...
}
@Silic0nS0ldier
Copy link
Author

This probably has some overlap with #483, regarding how JS handles JSON vs. everything else.

@fredrik-w
Copy link

I hit the same issue with [email protected], but thankfully they released 4.0.4 which fixes it. Though, for me, it was a transitive dependency so I had to override it in package.json:

  "resolutions": {
    "bl": "4.0.4"
  }

If you have a newer version of npm it's called overrides now. This, of course, only helps if there is a fixed version published afterwards.

@cgrindel
Copy link
Contributor

cgrindel commented Oct 5, 2022

@Silic0nS0ldier Has anyone proffered a fix to @codeceptjs/helper to remove the duplicate keys?

@cgrindel cgrindel added enhancement New feature or request discussion needed Discussion required to progress further labels Oct 5, 2022
@jbedard
Copy link
Member

jbedard commented Oct 8, 2022

This is due to bazelbuild/bazel#15605 and it needs to be fixed there. See also: #148

For now the only solution is patching the package.json like you've done.

@jbedard jbedard closed this as completed Oct 8, 2022
@thesayyn thesayyn removed the discussion needed Discussion required to progress further label Oct 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

5 participants