question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Link stylesheet didn't work

See original GitHub issue

Hi! This plugin is so usefull.

I’m trying to link a external CSS to my email template. Before this step the CSS was in HEAD section and this want a problem. But i want use SASS as pre-processor to make it simpler. So i need a external CSS file. But when i try to include the CSS file, inline-css print this in console:

{ Error: getaddrinfo ENOTFOUND main.css main.css:80
    at errnoException (dns.js:28:10)
    at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:79:26)
  code: 'ENOTFOUND',
  errno: 'ENOTFOUND',
  syscall: 'getaddrinfo',
  hostname: 'main.css',
  host: 'main.css',
  port: 80,
  response: undefined }

This is the code:

const fs = require('fs');
const inlineCss = require('inline-css');

fs.readFile('entry.html', 'utf8', (err, data) => {
    inlineCss(data, { url: './', removeHtmlSelectors: true }).then(html => {
        fs.writeFile('index.html', html);
    }).catch(function(reason) {
        console.log(reason);
    });
});

And this is the HTML:

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <link href="main.css" rel="stylesheet">
    </head>
<body>
...
</body>
</html>

I have also tried ‘/’, ‘.’.

I can’t understand where is the problem. In the example i link the file in the same way.

Thanks in advance!

Issue Analytics

  • State:open
  • Created 7 years ago
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

5reactions
daveycakescommented, Jun 15, 2017

Hey @AFerreli I had the same funny issue with the script looking one directory up from where I wanted. This was the solution: url = 'file://'+__dirname + '/' +path.dirname(file)+ '/';

The slash at the end made things work fine for me. It makes sense when you think about how this option is designed for arbitrary href urls, that a trailing slash would be good.

2reactions
matthewferrycommented, Jun 14, 2017

This seems a little odd to have to pass in file:// and __dirname or to have to use path module. In the most basic of setup using a linked stylesheet. Is there a strong use-case for the module not doing this for the user, so that it uses the current directory of the process?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Linking CSS doesn't work - Stack Overflow
Try to make the link the same level as index.html directed to the css folder.
Read more >
How to fix CSS not linking to your HTML document
When you add an external CSS file to your HTML document, you need to add the rel="stylesheet" attribute to the <link> tag to...
Read more >
CSS style sheet not loading or linking with HTML
I'm using HTML with Bootstrap all loads up fine, but when a style sheet is added to the HTML code sometimes it doesnt...
Read more >
How to add CSS - W3Schools
Each HTML page must include a reference to the external style sheet file inside the <link> element, inside the head section. Example. External...
Read more >
How to Fix CSS file is not Working with HTML in Chrome
Fix CSS file is not Working with HTML in Chrome | Problem Solved Show SupportBuy Me a COFFEE: https://buymeacoffee.com/Webjahin  ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found