trivago / prettier-plugin-twig-melody

Code formatting plugin for Prettier which can handle Twig/Melody templates
Apache License 2.0
155 stars 35 forks source link

Can't load plugins when using Yarn v2 #80

Open KarimTayel opened 3 years ago

KarimTayel commented 3 years ago

Hi,

I'm trying to use this plugin prettier-plugin-twig-enhancements, but every time I try to run Prettier it gives me an error:

Could not load plugin path node_modules/prettier-plugin-twig-enhancements

I tried to use yarn unplug prettier-plugin-twig-enhancements and point to the plugin folder inside the .yarn/unplugged folder but it didn't work either.

.prettierrc.js (Not Working)

module.exports = {
  ...
  plugins: ['prettier-plugin-twig-melody']
  twigMelodyPlugins: ['node_modules/prettier-plugin-twig-enhancements']
}

.prettierrc.js (Not Working)

module.exports = {
  ...
  plugins: ['prettier-plugin-twig-melody']
  twigMelodyPlugins: ['.yarn/unplugged/prettier-plugin-twig-enhancements-virtual-c783cdfae2/node_modules/prettier-plugin-twig-enhancements']
}

After many tries, the only working solution was to reference the plugin folder with an absolute path using Node.js Path API.

.prettierrc.js (Working)

const path = require('path');

module.exports = {
  ...
  plugins: ['prettier-plugin-twig-melody']
  twigMelodyPlugins: [
    `${path.resolve(
      '.yarn/unplugged/prettier-plugin-twig-enhancements-virtual-c783cdfae2/node_modules/prettier-plugin-twig-enhancements',
    )}`,
  ]
}