jerryc127 / hexo-theme-butterfly

🦋 A Hexo Theme: Butterfly
https://butterfly.js.org
Apache License 2.0
7.09k stars 1.28k forks source link

按照教程配置开启PWA,执行gulp命令后报错 #605

Closed kuole-o closed 3 years ago

kuole-o commented 3 years ago

I want to create a Bug report

Butterfly Information

Butterfly Version: 3.7.8

Platform: Windows

Browser: Chrome

Expected behavior

使用PWA,正常压缩打包完成

Actual behavior

使用PWA,按教程装完插件,执行gulp命令时,报错

Steps to reproduce the behavior

1.按教程安装gulpPWA,然后执行 gulp命令。 https://butterfly.js.org/posts/4073eda/#%E5%89%B5%E5%BB%BA-gulpfile-%E6%96%87%E4%BB%B6

Screenshots

image

Website

https://guole.fun/

Describe the bug

manifest.json 文件配置如下:

{
    "name": "guole's Blog",
    "short_name": "guole",
    "theme_color": "#49b1f5",
    "background_color": "#49b1f5",
    "display": "standalone",
    "scope": "/",
    "start_url": "/",
    "icons": [
        {
          "src": "https://cdn.guole.fun/logo/36.png",
          "sizes": "36x36",
          "type": "image/png"
        },
        {
            "src": "https://cdn.guole.fun/logo/48.png",
          "sizes": "48x48",
          "type": "image/png"
        },
        {
          "src": "https://cdn.guole.fun/logo/72.png",
          "sizes": "72x72",
          "type": "image/png"
        },
        {
          "src": "https://cdn.guole.fun/logo/96.png",
          "sizes": "96x96",
          "type": "image/png"
        },
        {
          "src": "https://cdn.guole.fun/logo/144.png",
          "sizes": "144x144",
          "type": "image/png"
        },
        {
          "src": "https://cdn.guole.fun/logo/192.png",
          "sizes": "192x192",
          "type": "image/png"
        },
        {
            "src": "https://cdn.guole.fun/logo/512.png",
            "sizes": "512x512",
            "type": "image/png"
          }
      ],
      "splash_pages": null
  }

gulp命令执行后的报错详情

PS E:\work\Git\butterfly> gulp
[09:12:56] Using gulpfile E:\work\Git\butterfly\gulpfile.js
[09:12:56] Starting 'default'...
[09:12:56] Starting 'generate-service-worker'...
[09:12:56] Finished 'generate-service-worker' after 802 ms
[09:12:56] Starting 'compress'...
[09:12:56] Starting 'minify-html'...
[09:12:57] Starting 'minify-css'...
[09:12:57] Starting 'minify-images'...
[09:12:57] Finished 'minify-images' after 85 ms
[09:12:57] gulp-imagemin: Couldn't load default plugin "gifsicle"
[09:12:57] gulp-imagemin: Couldn't load default plugin "optipng"
[09:13:03] gulp-imagemin: Couldn't load default plugin "gifsicle"
[09:13:03] gulp-imagemin: Couldn't load default plugin "optipng"
(node:17152) UnhandledPromiseRejectionWarning: Error: spawn E:\work\Git\butterfly\node_modules\mozjpeg\vendor\cjpeg.exe ENOENT
    at notFoundError (E:\work\Git\butterfly\node_modules\execa\node_modules\cross-spawn\lib\enoent.js:6:26)
    at verifyENOENT (E:\work\Git\butterfly\node_modules\execa\node_modules\cross-spawn\lib\enoent.js:40:16)
    at ChildProcess.cp.emit (E:\work\Git\butterfly\node_modules\execa\node_modules\cross-spawn\lib\enoent.js:27:25)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:277:12)
    at Process.callbackTrampoline (internal/async_hooks.js:131:14)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:17152) 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: 2)
(node:17152) [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.
[09:13:03] 'compress' errored after 6.71 s
[09:13:03] SyntaxError in plugin "gulp-babel"
Message:
    E:\work\Git\butterfly\public\js\style.js: Support for the experimental syntax 'jsx' isn't currently enabled (1:1):       

> 1 | <link rel="stylesheet" class="aplayer-secondary-style-marker" href="\css\APlayer.min.css"><script src="\js\APlayer.min.js" class="aplayer-secondary-script-marker"></script><script class="meting-secondary-script-marker" src="\js\Meting.min.js"></script>
    | ^

Add @babel/preset-react (https://git.io/JfeDR) to the 'presets' section of your Babel config to enable transformation.       
If you want to leave it as-is, add @babel/plugin-syntax-jsx (https://git.io/vb4yA) to the 'plugins' section to enable parsing.
[09:13:04] 'default' errored after 7.89 s
kuole-o commented 3 years ago

按照这里的方法,重新安装其中的一个插件也不行 npm install --save-dev @babel/preset-react https://stackoverflow.com/questions/65880113/react-add-babel-preset-react-https-git-io-jfedr-to-the-presets-section

kuole-o commented 3 years ago

我的package.json文件如下:

{
  "name": "hexo-site",
  "version": "0.0.0",
  "private": true,
  "scripts": {
    "build": "hexo generate",
    "clean": "hexo clean",
    "deploy": "hexo deploy",
    "server": "hexo server"
  },
  "hexo": {
    "version": "5.4.0"
  },
  "dependencies": {
    "-": "0.0.1",
    "aplayer": "^1.10.1",
    "gulp-html-minifier-terser": "^6.0.1",
    "hexo": "^5.4.0",
    "hexo-abbrlink": "^2.2.1",
    "hexo-blog-encrypt": "^3.1.6",
    "hexo-browsersync": "^0.3.0",
    "hexo-butterfly-douban": "^1.2.3",
    "hexo-deployer-git": "^3.0.0",
    "hexo-generator-archive": "^1.0.0",
    "hexo-generator-category": "^1.0.0",
    "hexo-generator-feed": "^3.0.0",
    "hexo-generator-index": "^2.0.0",
    "hexo-generator-search": "^2.4.3",
    "hexo-generator-sitemap": "^2.1.0",
    "hexo-generator-tag": "^1.0.0",
    "hexo-renderer-ejs": "^1.0.0",
    "hexo-renderer-jade": "^0.5.0",
    "hexo-renderer-marked": "^4.0.0",
    "hexo-renderer-pug": "^1.0.0",
    "hexo-renderer-stylus": "^2.0.1",
    "hexo-server": "^2.0.0",
    "hexo-tag-aplayer": "^3.0.4",
    "hexo-tag-bilibili": "^0.3.1",
    "hexo-theme-butterfly": "^3.7.8",
    "hexo-theme-landscape": "^0.0.3",
    "hexo-wordcount": "^6.0.1"
  },
  "devDependencies": {
    "@babel/core": "^7.14.6",
    "@babel/preset-env": "^7.14.7",
    "@babel/preset-react": "^7.14.5",
    "gulp": "^4.0.2",
    "gulp-babel": "^8.0.0",
    "gulp-clean-css": "^4.3.0",
    "gulp-htmlclean": "^2.7.22",
    "gulp-imagemin": "^7.1.0",
    "gulp-terser": "^2.0.1",
    "gulp-uglify": "^3.0.2",
    "workbox-build": "^6.1.5"
  }
}
jerryc127 commented 3 years ago

pwa 问题自己解决 而且看问题 E:\work\Git\butterfly\public\js\style.js 这是你自己diy的js吧 谷歌以下就有解决方法啦 https://stackoverflow.com/questions/63005011/support-for-the-experimental-syntax-jsx-isnt-currently-enabled https://github.com/babel/gulp-babel#usage

kuole-o commented 3 years ago

pwa 问题自己解决 而且看问题 E:\work\Git\butterfly\public\js\style.js 这是你自己diy的js吧 谷歌以下就有解决方法啦 https://stackoverflow.com/questions/63005011/support-for-the-experimental-syntax-jsx-isnt-currently-enabled https://github.com/babel/gulp-babel#usage

已解决,感谢

kuole-o commented 3 years ago

发现还有个小问题。本地编写的manifest.json没有问题,但部署后,自动在一开始插入了以下内容:

<link rel="stylesheet" class="aplayer-secondary-style-marker" href="\css\APlayer.min.css"><script src="\js\APlayer.min.js" class="aplayer-secondary-script-marker"></script><script class="meting-secondary-script-marker" src="\js\Meting.min.js"></script>

导致浏览器manifest.json报语法错误。麻烦老哥有空帮忙看看 也可以在我的网站上查看这个错误:https://guole.fun/

image

manifest.json源文件内容:

{
    "name": "guole's Blog",
    "short_name": "guole",
    "theme_color": "#49b1f5",
    "background_color": "#49b1f5",
    "display": "standalone",
    "scope": "/",
    "start_url": "/",
    "icons": [
        {
          "src": "https://cdn.guole.fun/logo/36.png",
          "sizes": "36x36",
          "type": "image/png"
        },
        {
            "src": "https://cdn.guole.fun/logo/48.png",
          "sizes": "48x48",
          "type": "image/png"
        },
        {
          "src": "https://cdn.guole.fun/logo/72.png",
          "sizes": "72x72",
          "type": "image/png"
        },
        {
          "src": "https://cdn.guole.fun/logo/96.png",
          "sizes": "96x96",
          "type": "image/png"
        },
        {
          "src": "https://cdn.guole.fun/logo/144.png",
          "sizes": "144x144",
          "type": "image/png"
        },
        {
          "src": "https://cdn.guole.fun/logo/192.png",
          "sizes": "192x192",
          "type": "image/png"
        },
        {
            "src": "https://cdn.guole.fun/logo/512.png",
            "sizes": "512x512",
            "type": "image/png"
          }
      ],
      "splash_pages": null
  }
kuole-o commented 3 years ago

image image

jerryc127 commented 3 years ago

aplayer 插件自带的插入会在所有文件开头都插入 div 所以你要么把你这个 manifest.json 写在exclude 要么用主题的aplayer插入 不要用aplayer的

多搜索多看文档

kuole-o commented 3 years ago

已解决!