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

[JS] unable to import subpackages (smoldot/worker, smoldot/bytecode, etc.) with parcel #1923

Open
voliva opened this issue Jul 31, 2024 · 4 comments · May be fixed by #1924
Open

[JS] unable to import subpackages (smoldot/worker, smoldot/bytecode, etc.) with parcel #1923

voliva opened this issue Jul 31, 2024 · 4 comments · May be fixed by #1924

Comments

@voliva
Copy link

voliva commented Jul 31, 2024

Some of the JS tooling is unable to resolve subpaths (smoldot/worker, smoldot/bytecode, smoldot/no-auto-bytecode). I could reproduce it with parcel in this repo + branch

> parcel src/index.html

(node:29823) [DEP0040] DeprecationWarning: The `punycode` module is deprecated. Please use a userland alternative instead.
(Use `node --trace-deprecation ...` to show where the warning was created)
Server running at http://localhost:1234
🚨 Build failed.

@parcel/core: Failed to resolve 'smoldot/worker' from './src/worker.ts'

  /Users/victor/development/papi/playgrounds/parcel/src/worker.ts:1:8
  > 1 | import "smoldot/worker";
  >   |        ^^^^^^^^^^^^^^^^
    2 | 

@parcel/resolver-default: Cannot load file './worker' from module 'smoldot'

I think this is due to missing a specific package.json on the root of smoldot package, every library that exports subpackages have them defined.

I'll open a PR with this.

@voliva voliva linked a pull request Jul 31, 2024 that will close this issue
@tomaka
Copy link
Contributor

tomaka commented Jul 31, 2024

I think this is due to missing a specific package.json on the root of smoldot package, every library that exports subpackages have them defined.

Smoldot is only one package, there's no "sub-package".
It uses the "exports" feature.
Parcel is supposed to support this feature, but maybe you need to do something like this?

@voliva
Copy link
Author

voliva commented Jul 31, 2024

Mhh I didn't realise it could configured on the resolver. I'm not using parcel on any project, I was just trying polkadot-api with different bundlers when I ran into this.

Typescript also doesn't support the exports feature if moduleResolution is set to node, but it does if it's set to bundler or nodenext, but if you use nodenext, then you can't target module: esNext.

My point is that "sub-packages" (which it's not any official term, it's the word I use when you import something from a subpath of a module, like smoldot/worker) were used to be defined with a separate package.json file, and there's tooling that depends on that. And some projects have to choose between one configuration or the other, and might be constrained to do those changes.

Happy to close this until someone can find any concrete example where they can't change their config to use the package.json's exports feature.

@tomaka
Copy link
Contributor

tomaka commented Jul 31, 2024

My point is that "sub-packages" (which it's not any official term, it's the word I use when you import something from a subpath of a module, like smoldot/worker) were used to be defined with a separate package.json file

But the entry points of smoldot are not "sub-packages". In order for them to be sub-packages, they would need to be more or less independent from each other, while in the case of smoldot the various files that define entry points are all entangled and import each other.

The rationale when we made it this way is that someone who uses smoldot with old tooling can still use smoldot using its easy-to-use default entry points. Using other entry points such as smoldot/worker is just an optimization.

@voliva
Copy link
Author

voliva commented Jul 31, 2024

My point is that "sub-packages" (which it's not any official term, it's the word I use when you import something from a subpath of a module, like smoldot/worker) were used to be defined with a separate package.json file

But the entry points of smoldot are not "sub-packages". In order for them to be sub-packages, they would need to be more or less independent from each other, while in the case of smoldot the various files that define entry points are all entangled and import each other.

My choice of words was not the correct one, sorry. Using your wording I meant entry point.

You can see the definition I've added in the PR is not actually specifying a new package, it doesn't have a name, nor dependencies by its own. It's just adding support for those resolvers that look at the smoldot's file or directory smoldot/worker when someone imports from smoldot/worker. When someone installs smoldot, it's bringing in all of these entry points.

Many other libraries, like RxJS, redux-toolkit, react-dom, or also polkadot-api have sub-path exports (or in other words, different entry points), and have this extra definition, on top of the top-level exports entry.

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

Successfully merging a pull request may close this issue.

2 participants