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?]: pnp nodeLinker causes 'package not found' with prettier plugins (uses import-meta-resolve) #6167

Closed
1 task done
francisu opened this issue Mar 12, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@francisu
Copy link
Contributor

Self-service

  • I'd be willing to implement a fix

Describe the bug

When using the prettier-svelte-plugin with prettier, yarn berry can't find the plugin.

% yarn lint
Checking formatting...
[error] Cannot find package 'prettier-plugin-svelte' imported from /private/tmp/sk/my-app/noop.js

To reproduce

npm create svelte@latest my-app
(select the defaults for the first two questions, and select 'add Prettier for code formatting' on the last question)
cd my-app
yarn set version berry
yarn install
yarn lint

Environment

System:
    OS: macOS 13.4.1
    CPU: (12) arm64 Apple M2 Pro
    Memory: 33.95 MB / 16.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 18.18.2 - /private/var/folders/rs/knxjxm3s1lj6b_z182f_1_lc0000gn/T/xfs-d67f466d/node
    Yarn: 4.1.1 - /private/var/folders/rs/knxjxm3s1lj6b_z182f_1_lc0000gn/T/xfs-d67f466d/yarn
  Managers:
    Homebrew: 4.0.26 - /opt/homebrew/bin/brew
    pip3: 23.1.2 - /Library/Frameworks/Python.framework/Versions/3.11/bin/pip3
    RubyGems: 3.0.3.1 - /usr/bin/gem
  Utilities:
    Make: 3.81 - /usr/bin/make
    GCC: 14.0.3 - /usr/bin/gcc
    Git: 2.39.2 - /usr/bin/git
    Clang: 14.0.3 - /usr/bin/clang
    Curl: 7.88.1 - /usr/bin/curl
  Servers:
    Apache: 2.4.56 - /usr/sbin/apachectl
  Virtualization:
    Docker: 24.0.5 - /usr/local/bin/docker
  IDEs:
    Emacs: 28.2 - /opt/homebrew/bin/emacs
    IntelliJ: 2023.2.5
    Vim: 9.0 - /usr/bin/vim
    Xcode: /undefined - /usr/bin/xcodebuild
  Languages:
    Bash: 3.2.57 - /bin/bash
    Perl: 5.30.3 - /usr/bin/perl
    Python3: 3.11.4 - /Library/Frameworks/Python.framework/Versions/3.11/bin/python3
    Ruby: 2.6.10 - /usr/bin/ruby
  Databases:
    SQLite: 3.39.5 - /usr/bin/sqlite3
  Browsers:
    Chrome: 122.0.6261.112
    Safari: 16.5.1

Additional context

The offending code in Prettier that's relevant is in import-from-file.js:

import { pathToFileURL } from "node:url";

// TODO: Use `import.meta.resolve` when it's available
import { resolve } from "import-meta-resolve";

function importFromFile(specifier, parent) {
  const url = resolve(specifier, pathToFileURL(parent).href);
  return import(url);
}

export default importFromFile;

This looks like it's going through some path to resolve the package that's not hitting the PnP monkey patch.

It looks like the problem might be fixable on the Prettier end, but I'm not sure how, and would like some help from the Yarn team for guidance. I'm willing to implement and test the fix for Prettier.

When I change the nodeLinker to be pnpm and rerun yarn install everything works fine.

@francisu francisu added the bug Something isn't working label Mar 12, 2024
@francisu francisu changed the title [Bug?]: pnp nodeLinker causes 'package not found' with prettier plugins [Bug?]: pnp nodeLinker causes 'package not found' with prettier plugins (uses import-meta-resolve) Mar 12, 2024
@francisu
Copy link
Contributor Author

The real issue is in import-meta-resolve: wooorm/import-meta-resolve#26

This is not a yarn issue.

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

No branches or pull requests

1 participant