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

Setting target option does not write any files ... #439

Open
eimfach opened this issue Mar 16, 2020 · 12 comments
Open

Setting target option does not write any files ... #439

eimfach opened this issue Mar 16, 2020 · 12 comments

Comments

@eimfach
Copy link

eimfach commented Mar 16, 2020

I have these options:

critical.generate({
  inline: true,
  src: 'index.html',
  width: 1300,
  height: 900,
  extract: true,
  base: './',
  target: {
    css: 'critical.css',
    html: 'index-critical.html',
    uncritical: 'uncritical.css'
  },
  ignore: {atrule: ['@charset']}
}).catch(function(err){
  throw err;
})

But it silently does not write any files ...

@bezoerb
Copy link
Collaborator

bezoerb commented Mar 16, 2020

which version of critical are you using?

@eimfach
Copy link
Author

eimfach commented Mar 16, 2020

1.3.9

@bezoerb
Copy link
Collaborator

bezoerb commented Mar 16, 2020

try installing the 2.x branch with npm i critical@next

@bezoerb
Copy link
Collaborator

bezoerb commented Mar 16, 2020

the documentation for the old version is at https://github.com/addyosmani/critical/tree/1.x

@eimfach
Copy link
Author

eimfach commented Mar 16, 2020

ah I see, okay thanks, will try that

@eimfach
Copy link
Author

eimfach commented Mar 16, 2020

Okay it writes the html file now and I changed target to target: 'index-critical.html'.
But it does not create a inline css style tag in the header where the critical css should be ...

@bezoerb
Copy link
Collaborator

bezoerb commented Mar 20, 2020

hmm... that's weird. Can you create a gist to reproduce?

@bezoerb
Copy link
Collaborator

bezoerb commented Apr 8, 2020

@eimfach: Any updates on this?

@lincolnaleixo
Copy link

not the OP but your solution to update to 2.0 version worked for me. thanks @bezoerb

@kentr
Copy link
Contributor

kentr commented Jun 4, 2022

I'm seeing the same thing on 4.0.1. In my case I'm using the html option and also outputting a css file, which is empty.

My guess is that critical is not actually generating the critical css, and so there's nothing to put into the html file.

@kentr
Copy link
Contributor

kentr commented Jun 4, 2022

Yeah, I confirmed that there is no generated css by using a callback to log the result.

The err parameter to the callback is null, so no errors to give clues.

Still debugging...

@kentr
Copy link
Contributor

kentr commented Jun 4, 2022

In my case it was due to an old configuration that's no longer supported AFAICT: Passing an html string or a local source file that contains links to remote stylesheets.

This appears to return "empty" stylesheet documents in getStyleseet().

In the debugging, I discovered that remote URLs are supported in the src parameter, but they will fail silently if the certificate is self-signed (such as in a dev environment). The NODE_TLS_REJECT_UNAUTHORIZED environment variable appears to have no effect on got, possibly because critical explicitly defaults to rejectUnauthorized: true.

For me, the solution was to use the actual URL in src instead of a string in html, and to set the request option with

{
  https: {
    rejectUnauthorized: false,
  },
}

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

No branches or pull requests

4 participants