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

Destination CSS file doesn't exist #70

Closed
NetOpWibby opened this issue Apr 19, 2016 · 12 comments
Closed

Destination CSS file doesn't exist #70

NetOpWibby opened this issue Apr 19, 2016 · 12 comments

Comments

@NetOpWibby
Copy link

Hey everyone,

I would like my Sass files to be compiled to a different folder, not the same folder as my Sass files, but dest isn't respected for some reason. Neither is outFile. Has anyone else gotten this to work?

@am11
Copy link
Collaborator

am11 commented Apr 20, 2016

Hi, can you share an example which is failing?

I have just tested https://github.com/andrew/node-sass-example with latest stable node-sass-middleware and connect (-> npm i node-sass-middleware connect), but could not reproduce the issue:

Changed:

var destPath = __dirname + '/public/styles/';

to:

var destPath = __dirname + '/public/new-styles/';

in server.js - line 5 and same line number in index.html as "new-styles/main.css" creates a new directory {cwd}/public/new-style with main.css on subsequent request.

@NetOpWibby
Copy link
Author

I was doing the exact same thing as the example you've tested with, but I'm not using Connect, I'm using FeathersJS.

@bnolan
Copy link

bnolan commented May 22, 2016

I'm having this on ocassional reloads using the example express code. Is this middleware kind of broken?

@BodySplash
Copy link

BodySplash commented May 24, 2016

I had the same issue, but then I realised it was just a matter of setting correctry the "prefix" option.
My pages look for css files with a path like "/styles/file.css"

here is my working conf :

{
    src: path.join(__dirname, 'scss'),
    dest: path.join(__dirname, 'public', 'styles'),
    prefix: '/styles'

}

Hope that helps

@Mr-Newlove
Copy link

Mr-Newlove commented Nov 20, 2016

I'm having the same issue, here is my middleware code:

  // adding the sass middleware
  app.use(sassMiddleware({
  	/* Options */
  	src: path.join(__dirname, "public/sass"),
  	dest: path.join(__dirname, "public/css"),
  	debug: true,
  	outputStyle: 'compressed',
    prefix:  '/static/css'  // Where prefix is at <link rel="stylesheets" href="prefix/style.css"/>
}));
app.use(express.static(path.join(__dirname, 'public')));

I get this on the console:

  source: ~\public\sass\style.scss
  dest: ~\public\css\style.css
  read: ~\public\css\style.css

But the css file is never rendered and the website doesnt recive the file.

Here is my dependency list from package.json for more info:

"dependencies": {
    "ejs": "~2.5.2",
    "express": "~4.14.0",
    "node-sass": "^3.13.0",
    "node-sass-middleware": "^0.10.0"
  }

@am11
Copy link
Collaborator

am11 commented Nov 21, 2016

@theshadow124, here is how I managed to make your example work:

File - c:\temp\projectx\my-server.js:

var sassMiddleware = require('node-sass-middleware');
var app = require('express')();
var serveStatic = require('serve-static');
var join = require('path').join;
var http = require('http');
var port = process.env.PORT || 8000;

var myPrefix = '/static/css';
var destination = join(__dirname, 'public/css');

// Sass middleware
app.use(sassMiddleware({
  /* Options */
  src: join(__dirname, 'public/sass'),
  dest: destination,
  debug: true,
  outputStyle: 'compressed',
  prefix: myPrefix 
}));

// static middleware
app.use(myPrefix, serveStatic(destination));

// start server
http.createServer(app).listen(port);

Assuming you have c:\temp\projectx\public\sass\test.scss source file; in a web browser, navigate to http://localhost:8000/static/css/test.css (notice the format: {protocol}://{host}:{port}/{prefix}/{cssFilename}.css).

@Mr-Newlove
Copy link

Mr-Newlove commented Nov 21, 2016

I never get the file no matter what, from my above post, it never saves the file even once.

I've also made a post on stackoverflow: http://stackoverflow.com/questions/40711155/node-sass-middleware-not-rendering-using-express

@am11
Copy link
Collaborator

am11 commented Nov 21, 2016

Ok, disregard my comment about destination slug (removed). Here is the example project: smw-test.zip

  • Extract zip smw-test.zip as smw-test/.
  • Then execute npm i && node my-server.
  • Browse to http://localhost:8000/static/css/test.css.

I was mistaken, we don't need to specify destination slug and static middleware should be configured as app.use(myPrefix, serveStatic(destination)); (fixed in above comment as well). Also the source and destination follow the same sub-directory structure, so if you call something like http://localhost:8000/static/css/some/sub/directory/test.css, then it looks the source file at the same structure under source directory like public/sass/some/sub/directory/test.scss.

@Mr-Newlove
Copy link

Great, I'm convinced it is some sort of permission issue at this point, even though I'm on windows. I ran your script, it ran fine, copied and pasted the content of your server file into mine and then it does the same thing. I've checked, the files are NOT read only.

I'll keep screwing with it.

@Mr-Newlove
Copy link

update to my issue, my filename was .sass, I thought this was valid, renaming to .scss fixed the issue

@am11
Copy link
Collaborator

am11 commented Jan 14, 2017

@NetOperatorWibby, I have tested the current behavior with connect and express multiple times: #70 (comment). Please try reconfiguring feather.js with node-sass-middleware v0.10.x. I am closing this for now.

Feel free to reopen or create a new issue (with steps to repro), if you are still getting problems.

@am11 am11 closed this as completed Jan 14, 2017
@NetOpWibby
Copy link
Author

@am11 I'm not using this anymore but I'm glad it works well now!

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

5 participants