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

Cannot resolve @ianvs/prettier-plugin-sort-imports (noop.js error) after cleaning node_modules #205

Open
1 task done
craftzcode opened this issue Feb 24, 2025 · 1 comment
Assignees

Comments

@craftzcode
Copy link

craftzcode commented Feb 24, 2025

Your Environment

  • Prettier version: ^3.5.2
  • node version: 23.7.0
  • package manager: [email protected]
  • IDE: Windsurf

Describe the bug

When using a shared Prettier configuration (in my case within a Turborepo setup) that includes @ianvs/prettier-plugin-sort-imports, everything works fine until I run cleaning scripts that remove all node_modules. After cleaning, even though I reinstall dependencies, running Prettier (via pnpm run format) results in an error that mentions a noop.js file. It appears that Prettier cannot locate the plugin module, even though it is listed as a dependency in my shared config.

To Reproduce

  1. Set up a Turborepo with a shared Prettier config package (e.g. @craftzcode/prettier-config) that includes:

    • @ianvs/prettier-plugin-sort-imports and prettier-plugin-tailwindcss in its dependencies.
    • A config file (index.js) exporting the Prettier configuration with a plugins array including the sort imports plugin.
  2. In one of the consuming packages (e.g. @craftzcode/ui), reference the shared config using the "prettier": "@craftzcode/prettier-config" field in package.json.

  3. Run the cleaning scripts:

pnpm run clean
pnpm run clean:workspaces

(These scripts run git clean -xdf .cache .turbo node_modules.)

  1. Reinstall dependencies using:
pnpm install
  1. Run the formatting command:
pnpm run format
  1. Observe the error referencing noop.js from @ianvs/prettier-plugin-sort-imports.

Expected behavior

Prettier should correctly resolve and load the @ianvs/prettier-plugin-sort-imports plugin even after cleaning and reinstalling dependencies, without error.

Screenshots, code sample, etc

Shared Prettier Config (@craftzcode/prettier-config/index.js):

/** @typedef {import("prettier").Config} PrettierConfig */
/** @typedef {import("@ianvs/prettier-plugin-sort-imports").PluginConfig} SortImportsConfig */
/** @typedef {import("prettier-plugin-tailwindcss").PluginOptions} TailwindConfig */

/** @type {PrettierConfig | SortImportsConfig | TailwindConfig} */
const config = {
  arrowParens: 'avoid',
  bracketSpacing: true,
  endOfLine: 'lf',
  jsxSingleQuote: true,
  singleQuote: true,
  semi: false,
  tabWidth: 2,
  trailingComma: 'none',
  plugins: [
    '@ianvs/prettier-plugin-sort-imports',
    'prettier-plugin-tailwindcss'
  ],
  importOrder: [
    '^(react/(.*)$)|^(react$)',
    '',
    '^(next/(.*)$)|^(next$)',
    '',
    '^(react-native(.*)$)',
    '^(expo(.*)$)|^(expo$)',
    '',
    '<THIRD_PARTY_MODULES>',
    '',
    '^(@trpc/(.*)$)|^(@trpc$)|^(@tanstack/(.*)$)|^(@tanstack$)',
    '',
    '^(drizzle-orm/(.*)$)|^(drizzle-orm$)|^(@/db/(.*)$)|^(@/db$)',
    '',
    '^@craftzcode/api/(.*)$',
    '',
    '^@craftzcode/db/(.*)$',
    '',
    '^@craftzcode/auth/(.*)$',
    '',
    '@/modules(.*)$',
    '',
    '^@/features/(.*)$',
    '',
    '^@/lib/(.*)$',
    '',
    '^@/hooks/(.*)$',
    '',
    'react-hook-form$',
    'zod$',
    '@hookform$',
    '',
    '^@craftzcode/ui/(.*)$',
    '^@/components/(.*)$',
    '',
    '^@/public/(.*)$',
    '',
    '^[./]'
  ],
  importOrderSeparation: false,
  importOrderSortSpecifiers: true,
  importOrderBuiltinModulesToTop: true,
  importOrderParserPlugins: ['typescript', 'jsx', 'decorators-legacy'],
  importOrderMergeDuplicateImports: true,
  importOrderCombineTypeAndValueImports: true
}

export default config

Consuming Package (@craftzcode/ui/package.json excerpt):

{
  "prettier": "@craftzcode/prettier-config",
  "devDependencies": {
    "@craftzcode/prettier-config": "workspace:*",
    ...
  }
}

Error log
Image

Additional Debugging Notes
- The issue only appears after running cleaning scripts (git clean -xdf .cache .turbo node_modules), which removes all installed packages.
- Reinstalling dependencies with pnpm install is required after cleaning; however, even after reinstallation, Prettier fails to load the plugin.
- Using Prettier version ^3.5.2 with Node 23.7.0 and [email protected].
- The shared config is using ESM ("type": "module" with export default config), and the plugin is correctly listed as a dependency.

Contribute to @ianvs/prettier-plugin-sort-imports

  • I'm willing to fix this bug 🥇
@fbartho
Copy link
Collaborator

fbartho commented Feb 24, 2025

Does this still happen with only prettier-plugin-tailwindcss? This sounds to me like a compatibility issue between pnpm and prettier, or a bug in pnpm!

It sounds like when you do something, it successfully works, but only after you hard-reset and pnpm install does something go weird?

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

3 participants