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

Can't find css-loader #2936

Open
captDaylight opened this issue Apr 18, 2019 · 54 comments
Open

Can't find css-loader #2936

captDaylight opened this issue Apr 18, 2019 · 54 comments
Labels

Comments

@captDaylight
Copy link

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.

@arjamizo
Copy link

arjamizo commented Apr 25, 2019

just apply those changes to your package.json

-    "node-sass": "^4.11.0",
-    "parcel-bundler": "^1.12.3",
+    "node-sass": "4.11.0",
+    "parcel-bundler": "1.12.3",

and of course remove package-lock.json so it can get recreated it using yarn,
if using nvm use npx yarn install or npx npm install or npx pnpm install

@DeMoorJasper
Copy link
Member

@arjamizo parcel does not rely on node-sass and sass is more reliable

Sent with GitHawk

@liviudobrea
Copy link

Also getting this with parcel@1.12.3, however this is not consistent, sometimes it will run, while at random times fail. Running with option --no-hmr seems to fix it. Therefore, I would use react-hot-loader manually untill fixed.

@brian32768
Copy link

Removing node-sass and reinstalling sass worked for me.

@rdhar
Copy link

rdhar commented May 24, 2019

Is this the same issue as #1931? I'm getting this same error on a project without any Sass; only one Stylus file so I doubt node-sass is to blame here.

@bichotll
Copy link

Having the same issue here. I couldn't figure out what is going on nor make it work.

Here the full error:

src.e31bb0bc.js:37 Uncaught (in promise) Error: Cannot find module '../node_modules/parcel-bundler/src/builtins/css-loader.js'
    at newRequire (src.e31bb0bc.js:37)
    at newRequire (prerelease.1b813e5e.js:29)
    at newRequire (prerelease.1b813e5e.js:21)
    at localRequire (prerelease.1b813e5e.js:53)
    at Object.parcelRequire.../node_modules/@fortawesome/fontawesome-free-webfonts/css/fontawesome.css._css_loader (jquery.js:10365)
    at newRequire (prerelease.1b813e5e.js:47)
    at localRequire (prerelease.1b813e5e.js:53)
    at Object.parcelRequire.index.js.jquery (index.js:2)
    at newRequire (prerelease.1b813e5e.js:47)
    at localRequire (prerelease.1b813e5e.js:53)

@theashguy
Copy link

I'm seeing this too. Happens during HMR, console message is in the browser. why would it be trying to resolve that path in the browser? or is this just an error being bubbled up over the websocket connection...

Attempting a rollback of the parcel package to see if I can get a working version.

@bichotll
Copy link

bichotll commented Jun 1, 2019 via email

@liviudobrea
Copy link

For the people who are struggling with this, just run parcel without hmr 'parcel run FILENAME - -no-hmr'.

However, by doing this you won't be able to hook into the hot module as it is going to be disabled.

@bichotll
Copy link

bichotll commented Jun 1, 2019 via email

@rdhar
Copy link

rdhar commented Jun 1, 2019

@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.

@liviudobrea
Copy link

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.

@rdhar
Copy link

rdhar commented Jun 4, 2019

@liviudobrea Just wanted to clarify not all of those are ways forward.


one of them is that of letting go of hmr and manually refreshing

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.

or setting up a webpack boilerplate with manual hmr integration of your choice

Again, suggesting to use a completely different alternative to Parcel.js is not a way forward. That's self-explanatory.

better one would be debugging the parcel builders and trying to figure out a fix for the issue

Hence, we arrive at #2936 in order to debug this issue and address it at the root. Which is why we're all here.

@mischnic
Copy link
Member

mischnic commented Jun 4, 2019

The only way to debug this issue is with some kind of reproduction.

@billcolumbia
Copy link

I'm running into this issue. Feel free to clone this and give it a shot.

JS reloads fine, CSS does not. Console log - Error: Cannot find module '../node_modules/parcel-bundler/src/builtins/css-loader.js'

Tried poking for a while to no avail. Hopefully this repo helps.

@mischnic
Copy link
Member

mischnic commented Jun 18, 2019

With that repo, changing the JS code throws "Uncaught SyntaxError: Unexpected end of input" (because it reloades too quickly before it's completely bundled?). That works again when import 'babel-polyfill' is removed

Changing the CSS does log that error

Using parcel's integrated dev server works as well.

This happens because the HMR runtime is packaged into a seperate JS file that isn't being loaded because Parcel is being used to bundle only specific files (e.g. parcel watch src/index.js src/style.css). This isn't ideal because you can't know if some extra scripts need to be loaded for HMR to work.

@mischnic mischnic added ✔️ Confirmed Bug HMR Hot Module Reloading labels Jun 18, 2019
@Bauerpauer
Copy link

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 to css-loader.js was necessary because bundle.getBaseURL(links[i].href) was returning http://localhost:8000/dist/css on each iteration and bundle.getBundleURL() returned http://localhost:8000/dist/js, preventing updateLink from ever being called.

Hopefully this can lead someone in the the direction of a proper fix, because this is definitely a hack ;)

index 819700f..d00c9bf 100644
--- packages/core/parcel-bundler/src/builtins/css-loader.js
+++ packages/core/parcel-bundler/src/builtins/css-loader.js
@@ -18,9 +18,9 @@ function reloadCSS() {
   cssTimeout = setTimeout(function () {
     var links = document.querySelectorAll('link[rel="stylesheet"]');
     for (var i = 0; i < links.length; i++) {
-      if (bundle.getBaseURL(links[i].href) === bundle.getBundleURL()) {
+      //if (bundle.getBaseURL(links[i].href) === bundle.getBundleURL()) {
         updateLink(links[i]);
-      }
+      // }
     }
 
     cssTimeout = null;
diff --git packages/core/parcel-bundler/src/packagers/JSPackager.js packages/core/parcel-bundler/src/packagers/JSPackager.js
index a07ff3b..c260b7b 100644
--- packages/core/parcel-bundler/src/packagers/JSPackager.js
+++ packages/core/parcel-bundler/src/packagers/JSPackager.js
@@ -218,6 +218,12 @@ class JSPackager extends Packager {
       entry.push(asset.id);
     }
 
+    let cssLoaderAsset = await this.bundler.getAsset(
+      require.resolve('../builtins/css-loader')
+    );
+    await this.addAssetToBundle(cssLoaderAsset);
+    entry.push(cssLoaderAsset.id);
+
     if (await this.writeBundleLoaders()) {
       entry.push(0);
     }

@syed-haroon
Copy link

syed-haroon commented Jun 26, 2019

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 directory npm install parcel-bundler then I started seeing this issue:

ENOENT: no such file or directory, open '/Users/user/.nvm/versions/node/v10.11.0/lib/node_modules/parcel-bundler/src/builtins/css-loader.js'

Here is the simple solution: just remove .cache and dist folder and run npm start again. This should fix the issue.

My package.json:

{
  "name": "myProject",
  "version": "1.0.0",
  "description": "My Project to explain Parcel issue",
  "main": "index.js",
  "scripts": {
    "start": "parcel index.html"
  },
  "keywords": [],
  "author": "Syed Haroon",
  "license": "ISC",
  "devDependencies": {
    "parcel-bundler": "^1.12.3"
  }
}

@Stradivario
Copy link
Contributor

Removing .cache and dist folder fixes the problem for me (It happens really rare and i always forgot what should i do :D)

The error i was having is this

Server running at http://localhost:1234 
🚨  /xxx/node_modules/parcel-bundler/src/builtins/css-loader.js: ENOENT: no such file or directory, open '/xxx/node_modules/parcel-bundler/src/builtins/css-loader.js'
Error: ENOENT: no such file or directory, open 'xxx/node_modules/parcel-bundler/src/builtins/css-loader.js'

@rdhar
Copy link

rdhar commented Jun 29, 2019

@syed-haroon and @Stradivario: With your fix applied (i.e., once you've deleted those folders), is the issue resolved permanently or does it still return occasionally?

@Bauerpauer
Copy link

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.

@mischnic
Copy link
Member

mischnic commented Jun 30, 2019

@Bauerpauer Could you please post your code?

@billcolumbia
Copy link

billcolumbia commented Jun 30, 2019 via email

@syed-haroon
Copy link

@syed-haroon and @Stradivario: With your fix applied (i.e., once you've deleted those folders), is the issue resolved permanently or does it still return occasionally?

Did not get the error so far. It's been like a week now.

@christian-beckmann
Copy link

christian-beckmann commented Jul 3, 2019

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.

@laurenthiernard
Copy link

laurenthiernard commented Jul 10, 2019

I have had the same problem and found the origin of it.
At the beginning I was building one page at a time. When I decided to have them linked on an index.html as an entry point for parcel to process everything, this issue appeared.
What I did is put a quick styling into a <style>...</style> tag on that page which was causing this 'builtins/css-loader.js' annoying error. All the other pages are associated with my main scss file otherwise.
I would think it's more of a syntax error than a problem linked to the modules

@Bauerpauer
Copy link

@lucaorio see my post w/ the diff above. Since I don't want to fight with trying to get Webpack working for my non-standard use case I've just been editing those 2 files to get CSS hot reloading working again.

epicserve added a commit to epicserve/django-base-site that referenced this issue Dec 2, 2019
There seems to be a bug in Parcel though preventing it from working (parcel-bundler/parcel#2936).
@cdll
Copy link

cdll commented Dec 20, 2019

same issue here~

humitos added a commit to PyCampES/pycampes that referenced this issue Feb 9, 2020
@Trollhag
Copy link

Solved by changing
"start": "parcel src/*.html"
to:
"start": "parcel src/NAME.html"

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.

@mcmire
Copy link

mcmire commented Mar 31, 2020

I am getting this as well. Does anyone know if this problem is fixed in v2?

@benavern
Copy link

benavern commented Apr 4, 2020

I have this issue too. the solution from @Trollhag doesn't work for me. Is this gonna be fixed soon ?

@ConstantinChirila
Copy link

Sorry to pile on, but the issue still happnes.

@c01nd01r
Copy link

c01nd01r commented Apr 14, 2020

Have this issue with style tags <style></style> in *.vue files.

@emirotin
Copy link

emirotin commented Apr 27, 2020

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:

  1. I only had to patch JSPackager
  2. I've pushed this code higher under the if (this.options.hmr) check
diff --git a/node_modules/parcel-bundler/src/packagers/JSPackager.js b/node_modules/parcel-bundler/src/packagers/JSPackager.js
index a07ff3b..8adcc67 100644
--- a/node_modules/parcel-bundler/src/packagers/JSPackager.js
+++ b/node_modules/parcel-bundler/src/packagers/JSPackager.js
@@ -216,6 +216,12 @@ class JSPackager extends Packager {
       );
       await this.addAssetToBundle(asset);
       entry.push(asset.id);
+
+      let cssLoaderAsset = await this.bundler.getAsset(
+        require.resolve('../builtins/css-loader')
+      );
+      await this.addAssetToBundle(cssLoaderAsset);
+      entry.push(cssLoaderAsset.id);
     }
 
     if (await this.writeBundleLoaders()) {

@Bauerpauer
Copy link

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.

@mischnic
Copy link
Member

parcel 2 on a recent project and had even more problems there

What did you run into?

@rdhar
Copy link

rdhar commented May 22, 2020

parcel 2 on a recent project and had even more problems there

What did you run into?

More problems, by the sounds of it...

@Bauerpauer
Copy link

@mischnic Sorry, I don't remember, it's been a few months and was in a rush, had to switch back to old version. If I run into 'em again I'll let ya know.

@tadinski
Copy link

tadinski commented Jul 9, 2020

what is the status on this?

@emirotin
Copy link

emirotin commented Jul 9, 2020

what is the status on this?

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

@tadinski
Copy link

tadinski commented Jul 9, 2020

what is the status on this?

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

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

@heggemsnes
Copy link

I had this issue and solved it by importing the css/scss file into a javascript file.

Inside index.js
import '../scss/main.scss';

@JackMorganNZ
Copy link

Is this issue planned to be fixed, or is it being left to be addressed in version 2? (if it's fixable there)

JackMorganNZ added a commit to uccser/dt-puzzle-journey that referenced this issue Sep 16, 2020
@flowen
Copy link

flowen commented Nov 10, 2020

I run into this error with any of the new CSS functions (e.g. min() max() clamp()) used in plain .css files.

I've seen different issues (but caused by a similar situation) in other packages where these (new) native functions don't mix with existing SASS functions.

I'm sorry I can't figure out if that's the actual case here, but this might help.

@cdll
Copy link

cdll commented Dec 16, 2020

the issue is still here :sad:

@PanuGr
Copy link

PanuGr commented Feb 10, 2021

Hi,
I am also getting this issue. I import my scss stylesheet from a .js file but I am getting this error when I try to add some css rules with a <style> tag.
A patch that is mentioned above feels overwhelming. Parcel was supposed to be easy and I am a beginner at this. I guess I will not add the <style> tag after all.

By the way, many people above mention using parcel 1.12. When I installed it, I got version 1.3.1. Is that some unstable version?

@danieldafoe
Copy link

@PanuGr I also have this problem–currently running version 1.12.4. Perhaps you're onto something with the version.

@eriksachse
Copy link

eriksachse commented Apr 20, 2021

I have the same problem. Caused by

import "./font_1.css";
import "./font_2.css";
import "./styles.css";

When I comment this line out, the error disappears and executes the following JS code.
Edit: Using

    <link rel="stylesheet" href="src/font_1.css" />
    <link rel="stylesheet" href="src/font_2.css" />
    <link rel="stylesheet" href="src/styles.css" />

Solves the error in the meantime.
Parcel 7.2.0

@adityamore
Copy link

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.

@peterkos
Copy link

peterkos commented Aug 4, 2021

Same issue here, Parcel 1.12.4; unfortunatley @emirotin's patch does not work for me :(

Might try to update to Parcel 2 but that will need a good chunk of a refactor to do so

@palachX
Copy link

palachX commented Oct 25, 2022

Hello guys, i don't how, but i solved this problem
This my steps

  1. delete directory node_modules

  2. delete package-lock.json

  3. npm install npm@latest -g

  4. npm install && npm install node-sass && npm install parcel

  5. Set u package.json script:
    "scripts": {
    "build": "parcel build index.html",
    "dev": "parcel index.html --open",
    "start": "npm run build && npm run dev",
    "test": "echo "Error: no test specified" && exit 1"
    }

  6. npm start

When u start 7 event npm must install :
"@parcel/packager-raw-url": "^2.7.0",
"@parcel/transformer-webmanifest": "^2.7.0"

And u package.json should become this screen

packge

I hope I helped you in solving your problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests