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

Can't set edition #307

Open
phil294 opened this issue Jun 18, 2024 · 5 comments
Open

Can't set edition #307

phil294 opened this issue Jun 18, 2024 · 5 comments

Comments

@phil294
Copy link

phil294 commented Jun 18, 2024

I'm developing a VSCode extension, this means CJS Node v18.

Running without any build step normally with const xyz = require('istextorbinary') works fine.

But when building with esbuild and running the resulting bundle, I get

editions-autoloader-package: Unable to determine a suitable edition for the package [/home/phi/b/search++/package.json] and entry [index.js] ↪editions-autoloader-editions-missing: No editions were specified.

so I thought it had to do with the exotic setup, so I changed it to require('istextorbinary/edition-es2022') instead. But this also doesn't work (at all):

Package subpath './edition-es2022' is not defined by "exports" in /home/phi/b/search++/node_modules/istextorbinary/package.json.

Well yes... it is, said file includes

"exports": {
  "node": {
    "require": "./edition-es2022/index.js"
    ...

I'm not familiar with neither npm's exports nor your editions tool, but something's not right here.

I also tried require('istextorbinary/require') but that yields the same output error (and the import is shown as invalid by tsserver).

So I went ahead and just deleted the entire "exports" section from your package.json locally. Now the sub-import works, but with ESBuild, the same error as before. The autoloader fails to determine a suitable edition. This makes no sense yet again, as I have already specified one, why is it still doing that?

And what do I do?

@balupton
Copy link
Member

Change your require or import statement to whichever entry in the editions section of the readme that you wish to require: https://github.com/bevry/istextorbinary#Editions

eg. require('istextorbinary/edition-es2022/index.js')

@phil294
Copy link
Author

phil294 commented Jun 18, 2024

I did that, this doesn't work as described. The extra /index.js doesn't change anything :/

@phil294
Copy link
Author

phil294 commented Jun 18, 2024

In fact, this is the require chain in my esbuild output:

var { isBinary } = require_edition_es2022();

in there, there's a

var textextensions_1 = __importDefault(require_textextensions());

which has a

module2.exports = require_edition_es52().requirePackage(...)

which runs the solicitEdition and fails. So I guess the problem is that textextensions doesn't inherit the selected edition?

Edit: Indeed, I have changed the requires inside isextorbinary/edition-es2022/index.js to

const textextensions_1 = __importDefault(require("textextensions/edition-es2022/index.js"));
// same for binaryextensions

and removed the exports fields from textextensions and binaryextensions... now it works in all scenarios. Pretty crazy workaround though

@phil294
Copy link
Author

phil294 commented Jun 18, 2024

And again, getting this far is only possible because I have removed the exports field from your package.json, without doing that it already fails at

Package subpath './edition-es2022/index.js' is not defined by "exports"

so this seems like two separate problems to me

phil294 added a commit to phil294/search-plus-plus-vscode-extension that referenced this issue Jun 18, 2024
needs custom node_modules overwrites atm
bevry/istextorbinary#307
@balupton
Copy link
Member

Hrmm, yeah, seems then specifying which edition you want depends upon loader support, which CI coverage is for Node.js's loader and direct URL/path support (Deno, Browsers, etc). So this seems to be an issue with the bundler/loader of VSCode. Or could be that the module specs have changed once again...

Perhaps the best way to workaround this, besides your hack in the OP. Is to update https://github.com/bevry/boundation to generate npm scripts and github actions to publish npm version tags for each edition, where it is the only edition in the bundle. Eg. textextensions@es2022 — this would also allow nested dep overrides.

The ideal resolution of course would be if the bundlers and loaders adopt/support the editions spec, as the Editions spec is superior, as detailed on https://github.com/bevry/editions

Might be best to continue here: bevry/editions#24

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