addyosmani / addyosmani/critical

UnhandledPromiseRejectionWarning: TypeError: parse is not a function

未關閉
#505 0 則留言 1 個 reaction 已指派 0 人 在 GitHub 檢視
主要語言
JavaScript
星號
10.3k
分支
390
PR 合併指標
30 天內沒有已合併 PR

描述

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]`)
}
})

貢獻指南

開啟貢獻指南

評估

這個 Issue 還沒有評估資料。

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。