cherry-markdown icon indicating copy to clipboard operation
cherry-markdown copied to clipboard

Nuxt3.js 下无法使用

Open shiLongLi-dot opened this issue 7 months ago • 2 comments

引入后构建失败,提示:

Error: Cannot read properties of undefined (reading 'userAgent')

⁃ (/node_modules/cherry-markdown/dist/cherry-markdown.esm.js:1531:24) ⁃ (/node_modules/cherry-markdown/dist/cherry-markdown.esm.js:6229:4) ⁃ at n (/node_modules/cherry-markdown/dist/cherry-markdown.esm.js:9:10) ⁃ (/node_modules/cherry-markdown/dist/cherry-markdown.esm.js:1529:9) ⁃ at ViteNodeRunner.runModule (/node_modules/vite-node/dist/client.mjs:354:9) ⁃ at ViteNodeRunner.directRequest (/node_modules/vite-node/dist/client.mjs:333:14) ⁃ at process.processTicksAndRejections (node:internal/process/task_queues:95:5) ⁃ at async ViteNodeRunner.cachedRequest (/node_modules/vite-node/dist/client.mjs:168:11) ⁃ at async ViteNodeRunner.dependencyRequest (/node_modules/vite-node/dist/client.mjs:216:10) ⁃ (async /components/tw-cherry-markdown/tw-cherry-markdown.vue:6:31)

[CAUSE] TypeError { stack: "Cannot read properties of undefined (reading 'userAgent')\n" + 'at /node_modules/cherry-markdown/dist/cherry-markdown.esm.js:1531:24)\n' + 'at /node_modules/cherry-markdown/dist/cherry-markdown.esm.js:6229:4)\n' + 'at n (/node_modules/cherry-markdown/dist/cherry-markdown.esm.js:9:10)\n' + 'at /node_modules/cherry-markdown/dist/cherry-markdown.esm.js:1529:9)\n' + 'at ViteNodeRunner.runModule (/node_modules/vite-node/dist/client.mjs:354:9)\n' + 'at ViteNodeRunner.directRequest (/node_modules/vite-node/dist/client.mjs:333:14)\n' + ' at process.processTicksAndRejections (node:internal/process/task_queues:95:5)\n' + 'at async ViteNodeRunner.cachedRequest (/node_modules/vite-node/dist/client.mjs:168:11)\n' + 'at async ViteNodeRunner.dependencyRequest (/node_modules/vite-node/dist/client.mjs:216:10)\n' + 'at asyn'... 91 more characters, message: "Cannot read properties of undefined (reading 'userAgent')", }

shiLongLi-dot avatar May 14 '25 04:05 shiLongLi-dot

node 版本: v20.13.1 "cherry-markdown": "^0.9.2", "nuxt": "^3.17.3", "vue": "^3.5.13", "vue-router": "^4.5.1"

study-nuxt.zip

shiLongLi-dot avatar May 14 '25 04:05 shiLongLi-dot

cherry-markdown暂时不支持SSR,可以先在nuxt.config.ts关闭SSR后使用,后续会支持SSR哈

export default defineNuxtConfig({ compatibilityDate: '2024-11-01', devtools: { enabled: true }, ssr: false, })

参考链接:https://nuxt.com.cn/docs/guide/concepts/rendering/

Saraph1nes avatar May 21 '25 03:05 Saraph1nes