You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I found two issues when using the @ vite pwa/vitepress plugin
One of them is the issue of installation and operation.
The issue with file output.
My speculation is that the srcDir setting in the VitePress configuration was not properly handled when processing the PWA build output directory outDir. When specifying srcDir as the src folder, the plugin's default generated. vitepress/dist directory incorrectly appears in the src folder. This indicates that the plugin did not make corresponding adjustments based on the value of srcDir when parsing the output directory.
import { defineConfig } from "vitepress";
import { withPwa } from "@vite-pwa/vitepress";
import pwaConfig from "./pwaConfig/index";
export default withPwa(defineConfig({
....
srcDir:'src',
pwd:pwaConfig,
}));
Error reported during code runtime
MacBook vitepress % yarn docs:dev
yarn run v1.22.17
warning package.json: No license field
$ vitepress dev
failed to load config from /Users/chenyaowen/vitepress/vitepress/.vitepress/config.mjs
failed to start server. error:
Cannot find package 'vite-plugin-pwa' imported from /Users/chenyaowen/vitepress/vitepress/node_modules/@vite-pwa/vitepress/dist/index.mjs
Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'vite-plugin-pwa' imported from /Users/chenyaowen/vitepress/vitepress/node_modules/@vite-pwa/vitepress/dist/index.mjs
at new NodeError (node:internal/errors:399:5)
at packageResolve (node:internal/modules/esm/resolve:889:9)
at moduleResolve (node:internal/modules/esm/resolve:938:20)
at defaultResolve (node:internal/modules/esm/resolve:1153:11)
at nextResolve (node:internal/modules/esm/loader:163:28)
at ESMLoader.resolve (node:internal/modules/esm/loader:838:30)
at ESMLoader.getModuleJob (node:internal/modules/esm/loader:424:18)
at ModuleWrap.<anonymous> (node:internal/modules/esm/module_job:77:40)
at link (node:internal/modules/esm/module_job:76:36)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
The device I am using is MacBook,,Node v18.16.0,yarn v1.22.17。When I tried to reinstall vite plugin pwa in my project, this issue was resolved, but I am very confused about it.
Now the content of my package.json article is as follows
I am a novice programmer and my English is not very good. There might be a lot of non-standard code. If my description is not detailed enough, or if there is anything you need me to provide, please feel free to tell me at any time.😅
Thank you for your guidance, I have succeeded. But there is a slight difference. I used the code you provided, but it prompted The requested module 'node: fs' does not provide an export named' dirname ', so I changed it to the following method, achieving my expected effect. 😋
中文版本:
在使用 @vite-pwa/vitepress 插件时,我发现了两个问题
1、其中一个是安装运行的问题。
2、文件输出的问题。
我的推测:在处理 PWA 构建输出目录 outDir 的时候,没有正确地处理 VitePress 配置中的 srcDir 设置。当指定 srcDir 为 src 文件夹时,插件默认生成的 .vitepress/dist 目录错误地出现在 src 文件夹内。这表明插件在解析输出目录时,没有根据 srcDir 的值进行相应的调整。
I found two issues when using the @ vite pwa/vitepress plugin
My speculation is that the srcDir setting in the VitePress configuration was not properly handled when processing the PWA build output directory outDir. When specifying srcDir as the src folder, the plugin's default generated. vitepress/dist directory incorrectly appears in the src folder. This indicates that the plugin did not make corresponding adjustments based on the value of srcDir when parsing the output directory.
My configuration process
install
pwaConfig.js
.vitePress/config.mjs
Error reported during code runtime
The device I am using is MacBook,,Node v18.16.0,yarn v1.22.17。When I tried to reinstall vite plugin pwa in my project, this issue was resolved, but I am very confused about it.
Now the content of my package.json article is as follows
I tried to execute the build command
The. vitepress/dist directory appears in my src directory,I tried deleting node.modules and reinstalling them, but it didn't work.
Some necessary screenshots
The text was updated successfully, but these errors were encountered: