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 摘要。