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

[Bug?]: #3879

Closed
1 task
coderaiser opened this issue Dec 15, 2021 · 5 comments
Closed
1 task

[Bug?]: #3879

coderaiser opened this issue Dec 15, 2021 · 5 comments
Labels
bug Something isn't working external bug This issue highlights a bug in another project

Comments

@coderaiser
Copy link
Contributor

coderaiser commented Dec 15, 2021

Self-service

  • I'd be willing to implement a fix

Describe the bug

When I'm using 🐊Putout code transformer with yarn P'n'P I got an error:

🐊 @putout/formatter-progress-bar: simport tried to access @putout/formatter-progress-bar, but it isn't declared in its dependencies; this makes the require call ambiguous and unsound.

Required package: @putout/formatter-progress-bar (via "@putout/formatter-progress-bar/package.json")
Required by: simport@npm:1.2.0 (via /Users/evgeny/Downloads/putout-yarn3/.yarn/cache/simport-npm-1.2.0-c4f61c3792-85716020b4.zip/node_modules/simport/simport.js)

The thing is simport is a module that improves dynamic imports in a couple ways:

  1. You can pass it as a function so instead of this monster:
    try {
         await import(pluginName);
    } catch {
    }

You can use:

const [error, plugin] = await tryToCatch(simport, pluginName);
  1. There is no need to destructure default:
const {default: plugin} = await import(pluginName);
const plugin = await simport(pluginName);
  1. Windows absolute paths just works:
const plugin = await simport('c:\windows');
  1. Supports json files, like with require.
  2. Extension can be dropped.
  3. etc.

So simport should not know about any dependency it is used for. Would be great to have first class support of it :)! Without using loose mode.

Related to coderaiser/putout#93, EvgenyOrekhov/eslint-config-hardcore#399

To reproduce

Steps to reproduce:

  1. git clone https://github.com/EvgenyOrekhov/putout-yarn3.git
  2. cd putout-yarn3
  3. yarn
  4. yarn putout .

Environment

error Command "dlx" not found.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

`yarn 1.17.3`
`v14.17.5`
`Mac OS`

Additional context

No response

@coderaiser coderaiser added the bug Something isn't working label Dec 15, 2021
@merceyz merceyz added the external bug This issue highlights a bug in another project label Dec 15, 2021
@merceyz
Copy link
Member

merceyz commented Dec 15, 2021

If simport wants to resolve something on behalf of another file it has to use https://nodejs.org/api/esm.html#importmetaresolvespecifier-parent, the way it currently does it just happens to work because of hoisting but it's fragile and prone to breaking.

See https://yarnpkg.com/advanced/rulebook/#packages-should-only-ever-require-what-they-formally-list-in-their-dependencies for more details on hoisting

@merceyz merceyz closed this as completed Dec 15, 2021
@coderaiser
Copy link
Contributor Author

@merceyz thanks for a quick reply!

OK, I can use a create-require hack, just to get .pnp.cjs 1MB monster to get working, and also I can get rid of simport and use simple-import.js file that should be copied in just every project, because of fragile and prone to breaking solution that works amazing with npm:

module.exports = async (url) => (await import(url)).default;

And I can publish new version of 🐊Putout that will be compatible with yarn P'n'P. But I have a problem with chalk and subpath patterns. Are they supported by yarn?

🐊 @putout/formatter-progress-bar: chalk tried to access #ansi-styles, but it isn't declared in its dependencies; this makes the require call ambiguous and unsound.

Required package: #ansi-styles (via "#ansi-styles/package.json")
Required by: chalk@npm:5.0.0 (via /Users/coderaiser/putout-yarn3/.yarn/cache/chalk-npm-5.0.0-7be183234e-6eba7c518b.zip/node_modules/chalk/source/index.js)

ansi-styles doesn't even have package.json!

@merceyz
Copy link
Member

merceyz commented Dec 15, 2021

that works amazing with npm:

With your current dependency tree that might be true but that isn't guaranteed and, like the documentation I linked shows, can break by unrelated changes to the dependency tree.

But I have a problem with chalk and subpath patterns. Are they supported by yarn?

The imports field isn't supported by PnP yet, no.
Ref #3843

@coderaiser
Copy link
Contributor Author

@merceyz thank you!

I think this information could be important for @sindresorhus (there is no ability to create an issue in chalk repository, so if you will see this message, would be great to have support of Yarn PnP).

@rachelslurs
Copy link

@coderaiser Looking through some of the closed issues over at chalk, I guess chalk is taking a hard stance on not wanting to support people not supporting imports and exports in their package.json. They would rather you just use chalk v4 I suppose. 😕 Surprising given how many projects use chalk. 😬

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working external bug This issue highlights a bug in another project
Projects
None yet
Development

No branches or pull requests

3 participants