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

'javascript.builtins.Array.at' is unknown #16

Open
jaswrks opened this issue Sep 17, 2023 · 7 comments
Open

'javascript.builtins.Array.at' is unknown #16

jaswrks opened this issue Sep 17, 2023 · 7 comments

Comments

@jaswrks
Copy link

jaswrks commented Sep 17, 2023

Occurs on Node 20.5.1 running 2.1.0.

TypeError: The given feature: 'javascript.builtins.Array.at' is unknown. It must be a valid Caniuse or MDN feature!

I noticed the MDN import changed to a glob * import in the latest release. Not sure if that has something to do with it, but I was getting some warnings about experimental use of JSON import assertions also. If I revert back to previous version of browserslist-generator, all is fine. Still get the warning about experimental import assertions, though.

@jaswrks
Copy link
Author

jaswrks commented Sep 17, 2023

(node:47818) ExperimentalWarning: Import assertions are not a stable feature of the JavaScript language. Avoid relying on their current behavior and syntax as those might change in a future version of Node.js.
(Use `node --trace-warnings ...` to show where the warning was created)
TypeError: The given feature: 'javascript.builtins.Array.at' is unknown. It must be a valid Caniuse or MDN feature!
    at assertKnownFeature (.../node_modules/browserslist-generator/dist/esm/index.js:1175:15)
    at getFeatureSupport (.../node_modules/browserslist-generator/dist/esm/index.js:1194:5)
    at browserSupportForFeaturesCommon (.../node_modules/browserslist-generator/dist/esm/index.js:1317:25)
    at browsersWithSupportForFeatures (.../node_modules/browserslist-generator/dist/esm/index.js:974:33)
    at browsersWithSupportForEcmaVersion (.../node_modules/browserslist-generator/dist/esm/index.js:1058:20)
    at Module.default (.../dev/.files/bin/browserslist/index.mjs:62:46)
    at BrowsersList.update (.../dev/.files/bin/update.mjs:227:98)
    at async BrowsersList.run (.../dev/.files/bin/update.mjs:210:3)
    at async Object.handler (.../dev/.files/bin/update.mjs:859:5)

@mems
Copy link

mems commented Sep 21, 2023

I've got the same issue and I thing it's related to this line:

import * as compatData from "@mdn/browser-compat-data" assert {type: "json"};

When executed in Node 19.2 imported from an ES module, because of the namespace import (* as), compatData is equal to Module {default: Accessor, Symbol(Symbol.toStringTag): "Module"}
That means if you want to read javascript.builtins.Array.at, you need to access it as compatData.default.javascript.builtins.Array.at.

@laverdet
Copy link

Thanks @mems, I patched this locally and it works:

diff --git a/dist/esm/index.js b/dist/esm/index.js
index 5f01ddfca542c54ffedced4d4489aff4843d6067..2180bc326bd27c4c0d088aa06af185aadbd0b22b 100644
--- a/dist/esm/index.js
+++ b/dist/esm/index.js
@@ -1,6 +1,6 @@
 import Browserslist from 'browserslist';
 import { feature, features } from 'caniuse-lite';
-import * as compatData from '@mdn/browser-compat-data' assert { type: 'json' };
+import compatData from '@mdn/browser-compat-data' assert { type: 'json' };
 import objectPath from 'object-path';
 import { coerce, lt, gt, gte, lte } from 'semver';
 import { UAParser } from 'ua-parser-js';

@jaswrks
Copy link
Author

jaswrks commented Nov 26, 2023

Thanks so much. Is there an ETA on when there will be a release available that patches this?

@mems
Copy link

mems commented Nov 4, 2024

I tried with the new version v3 but still have the same issue.

I tried to understand why this is not an blocking issue when release new versions (since then we have have few more versions)
After investigating a bit, I found the problem. I think it's comes from how TypeScript handle import of JSON (but I'm not a TS user). I can easliy reproduce it when I using the source of test suite of browserslist-generator.

With the following package.json, execute npm install. Then run npm run test and npm run test-ts.

You will get something like:

> npm run test
[...]
ℹ tests 147
ℹ suites 0
ℹ pass 67
ℹ fail 80
ℹ cancelled 0
ℹ skipped 0
ℹ todo 0
ℹ duration_ms 1290.7176
[...]

> npm run test-ts
[...]
ℹ tests 147
ℹ suites 0
ℹ pass 147
ℹ fail 0
ℹ cancelled 0
ℹ skipped 0
ℹ todo 0
ℹ duration_ms 3270.8962

It fail with pure (lot of "TypeError [Error]: The given feature: '${feature}' is unknown. It must be a valid Caniuse or MDN feature!"), but it pass with TS.

package.json

It download browserslist-generator.test.js from the browserslist-generator repo, update an import (to use browserslist-generator instead of sources) and install browserslist-generator, tsx and useragent-generator

{
  "name": "browserslist-generator-test",
  "version": "1.0.0",
  "main": "index.js",
  "scripts": {
    "prepare": "curl -s https://raw.githubusercontent.com/wessberg/browserslist-generator/refs/heads/master/test/browserslist-generator.test.ts | sed 's|../src/index.js|browserslist-generator|g' > browserslist-generator.test.js",
    "test": "node --test browserslist-generator.test.js",
    "test-ts": "node --import tsx --test browserslist-generator.test.js"
  },
  "type": "module",
  "dependencies": {
    "browserslist-generator": "^3.0.0",
    "tsx": "^4.19.2",
    "useragent-generator": "^1.1.0"
  }
}

@mems
Copy link

mems commented Nov 5, 2024

With the version 3.0.0, I use patch-package with the following patch patches/browserslist-generator+3.0.0.patch:

This patch fix the issue https://github.com/wessberg/browserslist-generator/issues/16

diff --git a/node_modules/browserslist-generator/dist/index.js b/node_modules/browserslist-generator/dist/index.js
index a7640d4..76645e8 100644
--- a/node_modules/browserslist-generator/dist/index.js
+++ b/node_modules/browserslist-generator/dist/index.js
@@ -1,7 +1,7 @@
 // src/browserslist-generator/browserslist-generator.ts
 import Browserslist2 from "browserslist";
 import { feature as caniuseFeature, features as caniuseFeatures } from "caniuse-lite";
-import * as compatData from "@mdn/browser-compat-data" with { type: "json" };
+import compatData from "@mdn/browser-compat-data" with { type: "json" };
 import objectPath from "object-path";
 import { gt as gt2, gte as gte3, lt as lt2, lte as lte2 } from "semver";
 

@bosconian-dynamics
Copy link

Related: #19

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

4 participants