parcel: Can't find css-loader
Error: ENOENT: no such file or directory, open '/Users/paulchristophe/projects/return-interface/node_modules/parcel-bundler/src/builtins/css-loader.js'
Configuration was working then all of a sudden stopped. I’ve tried removing my node_modules
and re-installing but no dice.
About this issue
- Original URL
- State: open
- Created 5 years ago
- Reactions: 3
- Comments: 54 (6 by maintainers)
Commits related to this issue
- Attempt to fix live reload ... There seems to be a bug in Parcel though preventing it from working (https://github.com/parcel-bundler/parcel/issues/2936). — committed to epicserve/django-base-site by epicserve 5 years ago
- Disable hot module reload in parcel (css-loader not found) It produces this issue https://github.com/parcel-bundler/parcel/issues/2936 — committed to PyCampES/pycampes by humitos 4 years ago
- Add patch to fix Parcel HMR issue See: https://github.com/parcel-bundler/parcel/issues/2936 — committed to uccser/dt-puzzle-journey by JackMorganNZ 4 years ago
I have this problem when I try to start with multiple sources and have the posthtml-include module active.
Solved by changing
"start": "parcel src/*.html"
to:"start": "parcel src/NAME.html"
and working on one page at a time.Not ideal, as working on multiple pages is a very common thing to do.
Same issue here with an Scss file. I’m using parcel 1.12.4 and serve the files with the custom express server (a hard requirement for this project) which serves the dist folder as well as doing some API handling.
HTML and JS HMR works, CSS is throwing the same css-loader error.
Following @Bauerpauer’s idea I’ve patched parcel-bundler (using
patch-package
) and it seems to be working fine.The two differences to my approach:
JSPackager
if (this.options.hmr)
check@liviudobrea Just wanted to clarify not all of those are ways forward.
That is sacrificing one of the major features of Parcel.js. It’s #2 on the Features page. I don’t see that as an acceptable way forward.
Again, suggesting to use a completely different alternative to Parcel.js is not a way forward. That’s self-explanatory.
Hence, we arrive at #2936 in order to debug this issue and address it at the root. Which is why we’re all here.
Indeed it would disable Hmr, as I have mentioned. You have therefore multiple ways going forward, one of them is that of letting go of hmr and manually refreshing. Another better one would be debugging the parcel builders and trying to figure out a fix for the issue, or setting up a webpack boilerplate with manual hmr integration of your choice. Best of luck.
I had this issue and solved it by importing the css/scss file into a javascript file.
Inside index.js
import '../scss/main.scss';
I also run into this error. Removing dist or .cache folder does not solve it. I use multiple HTML pages, index.html links - with iframes embedded - to the other pages. If starting with index.html without linking to the other pages - which also include the same CSS files - there is no error.
With linking to the other pages, including also those CSS files, I ran into that error.
Running serve with a subpage as endpoint, then the error does not appear. But if I navigate to another endpoint page it appears too.
Notice: if starting a page - which is not linked with the other pages, there is no error. So embedding direct links causes those error - when navigate to another endpoint, which is “connected” to each other.
Even I had the same issue, first I installed parcel globally
npm install -g parcel-bundler
but later I uninstalled Parcel globally and installed it in my local project directorynpm install parcel-bundler
then I started seeing this issue:Here is the simple solution: just remove
.cache
anddist
folder and runnpm start
again. This should fix the issue.My package.json:
More problems, by the sounds of it…
I am getting this issue with 1.12.4 too. My build script is a simple
parcel build index.html
and my css import is done through the link tag. Nothing in the thread really helps me.Removing .cache and dist folder fixes the problem for me (It happens really rare and i always forgot what should i do 😄)
The error i was having is this
@liviudobrea Wouldn’t that prevent automatic reloading on file-save (aka HMR), thereby negating one of the main features of Parcel.js with running
parcel index.html
in the first place?At that point, you may as well just run
parcel build index.html
since that just produces the production-ready package directly without the need for HMR at all. In this case, I’m not sure--no-hmr
is a workaround as much as a completely separate process.the issue is still here :sad:
Thanks @emirotin! I didn’t know about
patch-package
- that’s gonna save me a lot of frustration! I tried moving to parcel 2 on a recent project and had even more problems there - so I’m sticking w/ 1.12.4 for the forseable future.I have this issue too. the solution from @Trollhag doesn’t work for me. Is this gonna be fixed soon ?
Thanks, it works! Appreciate taking your time looking into this and posting the solution. Parcel was supposed to be an easy thing. Ended up spending more time on it than webpack
Your best bet to quickly fix it now is to use my patch and https://www.npmjs.com/package/patch-package You do it once and it just works
I managed to get this to work as well;
parcel src/{file,file2,file3}.js
Still not ideal, but better than working on a single file at the time.
Removing .cache has no effect for me. I don’t have a dist folder. Also, @Stradivario’s reported error is not the same as the one I’m experiencing (reported by @bichotll, @billcolumbia). Seems like there are 2 separate problems here.
I dug into this today and found that the following changes make css hot reloading work again, at least for the sample repo posted by @billcolumbia above. I don’t know the project well enough to describe my change to
JSPackager.js
, but I found that my change injected the module that the error is yelling about. The change tocss-loader.js
was necessary becausebundle.getBaseURL(links[i].href)
was returninghttp://localhost:8000/dist/css
on each iteration andbundle.getBundleURL()
returnedhttp://localhost:8000/dist/js
, preventingupdateLink
from ever being called.Hopefully this can lead someone in the the direction of a proper fix, because this is definitely a hack 😉