Open 1natsu172 opened 1 week ago
Do you forget to install postcss? happy-css-modules requires postcss.
@mizdra Yes. Strictly...the vite
supports postcss/sass/less and has these deps, so it is present in node_modules.
The following are the results during the process of debugging. I'm not completely sure, but perhaps may be stepping on some chaos around pnpm symlink and hoist and node resolve.
In the case of pnpm
I did pnpm add -D postcss
instead of as project devDeps instead of implicit deps. But hcm seems to be judging implicit deps (less and sass) as "installedPeerDeps" as a result of import.meta.resolve
. As a result, it's trying to create cache keys for [postcss, less, sass] with createNpmPackageKey
.
Apparently @file-cache/npm
uses browserify's resolve
package, where it fails to resolve less and sass, which are implicit deps.
In the case of npm
npm does not hoist and create symlink in like .pnpm
. It to be able to resolve path in node_modules/postcss
even if it's implicit deps. So npm works fine with vite+hcm without explicit postcss devDeps.
My debugging intuition to tell me that this may not be hcm's liability issue… 🤔 I will report back if there is any progress in debugging.
@mizdra Sorry, the first repro was incomplete. Please disregard the first one. I've prepared a new correct repro. The basics are outlined in the README.
https://github.com/1natsu172/vite-pnpm-module-resolve-repro
This issue is quite an edge case , but it can be understood as a problem where "hcm stops working If less
or sass
is installed unintentionally"
Through debugging, even if postcss
is included in devDeps, if less
and sass
are present in node_modules as side effects, everything gets consolidated in one place. Thus hcm resolved less
and sass
as "installed" using import.meta.resolve
.
However, since the core of @file-cache/npm
is located in a different directory, it seems unable to find less
and sass
(this includes a bit of guess).
Report
I was tried to use happy-css-modules on my project that using
pnpm@9
. But I face to error the below message.From the error message, it seemed to be around cache implementation, so I set cache option flag to disable and it has been found to work fine.
reproduction
https://stackblitz.com/edit/vitejs-vite-az9mty?file=package.jsonThis sandbox is created from vite template(https://ja.vitejs.dev/guide/). And switch to pnpm from default npm(deletedpackage-lock.json
and first creatednode_modules
then re-runpnpm install
).You can run command on the stackblitz terminal.pnpm run hcm
pnpm run hcm --cache=false
By the way
I have confirmed once that
npm exec hcm 'src/**/*.module.{css,scss,less}'
works without any problem in npm project environment.I'm not sure if the cause is in
@fine-cache
or in the implement aroundimport.meta.resolve
. I really wanted to run a test of the this repo, but since this repository wasnpm-workspaces
, I decided to report this once and for a moment.