Description
We have been using critical package to generate critical css for our Next JS application. Now we are getting the following error.
UnhandledPromiseRejectionWarning: TypeError: parse is not a function
at compileUnsafe (D:--path--\node_modules\css-select\lib\compile.js:31:14)
at select (D:--path--\node_modules\css-select\index.js:18:49)
at CSSselect (D:--path--\node_modules\css-select\index.js:41:9)
at initialize.exports.find (D:--path--\node_modules\cheerio\lib\api\traversing.js:40:21)
at initialize.module.exports (D:--path--\node_modules\cheerio\lib\cheerio.js:86:18)
at new initialize (D:--path--\node_modules\cheerio\lib\static.js:29:20)
at initialize (D:--path--\node_modules\cheerio\lib\static.js:26:14)
at oust (D:--path--\node_modules\oust\index.js:72:37)
at Function.module.exports.raw (D:--path--\node_modules\oust\index.js:98:37)
at getStylesheetHrefs (D:--path--\node_modules\critical\src\file.js:370:28)
(node:18364) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag --unhandled-rejections=strict
(see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:18364) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
We have written a custom script to fetch the HTML file path and generate for each HTML. This is a sample of code snippent.
critical.generate({
base: './',
src: files[i], // files array has list of all the files and we are looping through the array
target: files[i],
minify: true,
inline: true,
dimensions: [{
width: 414,
height: 736
}, {
width: 768,
height: 1024
}, {
height: 900,
width: 1200,
}],
ignore: ['@font-face']
},(err, output) => {
if(err) {
console.info(Critical css generation failed ${err}
)
}
else if(output) {
console.info(${i} success: ${files[i]} [critical css generated]
)
}
})