Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vs code debugging vite+vue3 project breakpoints cannot point to source code #18004

Closed
7 tasks done
qinfeng0214 opened this issue Sep 3, 2024 · 2 comments
Closed
7 tasks done

Comments

@qinfeng0214
Copy link

Describe the bug

Hello everyone, I want to use vs code to debug my vite+vue3 project. I configured the launch.json file and added the debugger, then started vs code debugging mode, but it stopped at the compiled debugger. I expect it to stop at the debugger of the source code. What should I do? Thank you

Reproduction

null

Steps to reproduce

launch.json:

{
  "version": "0.2.0",
  "configurations": [
    {
      "type": "chrome", // 调试器运行环境
      "request": "launch",
      "name": "debug chrome",
      // "url": "http://abc.console.new.cloud.com:4101",
      "url": "http://127.0.0.1:4101",
      "webRoot": "${workspaceFolder}", // 项目根目录
      "userDataDir": false, // chrome 保存的用户数据目录
      "sourceMapPathOverrides": {
        // "http://abc.console.new.cloud.com:4101/*": "${webRoot}/*"
      }
    }
  ]
}

vite.config.js

import { fileURLToPath, URL } from 'node:url';
import path from 'path';
import fs from 'fs';
import { defineConfig, loadEnv } from 'vite';
import vue from '@vitejs/plugin-vue';
import vueJsx from '@vitejs/plugin-vue-jsx';
import viteCompression from 'vite-plugin-compression';
import vueSetupExtend from 'vite-plugin-vue-setup-extend';
import viteImagemin from 'vite-plugin-imagemin';
import { createSvgIconsPlugin } from 'vite-plugin-svg-icons';
import { visualizer } from 'rollup-plugin-visualizer';
import qiankun from 'vite-plugin-qiankun';
import { KingDesignResolver } from '@ksconsole/kingdesignresolver';
import Components from 'unplugin-vue-components/vite';

// Automatically include styles from ElementPlus components
const optimizeDepsElementPlusInclude = ['element-plus/es'];
fs.readdirSync('node_modules/element-plus/es/components').forEach((dirname) => {
  const stylePath = `node_modules/element-plus/es/components/${dirname}/style/css`;
  if (fs.existsSync(stylePath)) {
    optimizeDepsElementPlusInclude.push(stylePath);
  }
});
const pastName = 'ksc-system-manage';
// Define base Vite configuration
export default defineConfig(({ mode }) => {
  // 根据当前工作目录中的 `mode` 加载 .env 文件
  // 设置第三个参数为 '' 来加载所有环境变量,而不管是否有 `VITE_` 前缀。
  const env = loadEnv(mode, process.cwd() + '/env');
  const isAnalyze = mode === 'analyze';
  return {
    base: env.VITE_BASE_URL || '/',
    resolve: {
      alias: {
        '@': fileURLToPath(new URL('./src', import.meta.url)),
        mockjs: fileURLToPath(new URL('./virtuals/mock.js', import.meta.url)),
      },
    },
    server: {
      port: 4100,
      // host: 'abc.console.new.cloud.com',
      // origin: 'http://abc.console.new.cloud.com:4100',
      host: '127.0.0.1',
      hmr: true,
      strictPort: false,
      open: true,
      proxy: {
        '/api': {
          target: 'http://xxxxxxx',
          changeOrigin: true,
          secure: false,
        }
        },
      },
    },
    css: {
      preprocessorOptions: {
        less: {
          math: 'always',
        },
      },
    },
    optimizeDeps: {
      include: optimizeDepsElementPlusInclude,
    },
    plugins: [
      vue(),
      Components({
        resolvers: [KingDesignResolver()],
      }),
      vueJsx(),
      vueSetupExtend(),
      createSvgIconsPlugin({
        iconDirs: [path.resolve(process.cwd(), 'src/svg')],
        symbolId: 'icon-[dir]-[name]',
      }),
      qiankun(pastName, { useDevMode: true }),
      viteCompression({
        verbose: true,
        disable: false,
        threshold: 10240,
        algorithm: 'gzip',
        ext: '.gz',
        deleteOriginFile: false,
      }),
      viteImagemin(),
      ...(isAnalyze ? [visualizer()] : []),
    ],
    build: {
      outDir: 'dist',
      assetsDir: 'assets',
      sourcemap: false,
      minify: 'terser',
    },
  };
});

System Info

system:macOS
browsers: Google Chrome

Used Package Manager

pnpm

Logs

<anonymous> ([127.0.0.1](http://127.0.0.1/)꞉4101/src/views/Organization/workplace/application/index.vue?t=1725331386688:240)
callWithErrorHandling (/Users/yft/work/ksc-system-manage/node_modules/.pnpm/@vue+runtime-core@3.4.27/node_modules/@vue/runtime-core/dist/runtime-core.esm-bundler.js:195)
callWithAsyncErrorHandling (/Users/yft/work/ksc-system-manage/node_modules/.pnpm/@vue+runtime-core@3.4.27/node_modules/@vue/runtime-core/dist/runtime-core.esm-bundler.js:202)
job (/Users/yft/work/ksc-system-manage/node_modules/.pnpm/@vue+runtime-core@3.4.27/node_modules/@vue/runtime-core/dist/runtime-core.esm-bundler.js:1955)
callWithErrorHandling (/Users/yft/work/ksc-system-manage/node_modules/.pnpm/@vue+runtime-core@3.4.27/node_modules/@vue/runtime-core/dist/runtime-core.esm-bundler.js:195)
flushJobs (/Users/yft/work/ksc-system-manage/node_modules/.pnpm/@vue+runtime-core@3.4.27/node_modules/@vue/runtime-core/dist/runtime-core.esm-bundler.js:410)
Promise.then (未知源:0)
queueFlush (/Users/yft/work/ksc-system-manage/node_modules/.pnpm/@vue+runtime-core@3.4.27/node_modules/@vue/runtime-core/dist/runtime-core.esm-bundler.js:319)
queuePostFlushCb (/Users/yft/work/ksc-system-manage/node_modules/.pnpm/@vue+runtime-core@3.4.27/node_modules/@vue/runtime-core/dist/runtime-core.esm-bundler.js:339)
queueEffectWithSuspense (/Users/yft/work/ksc-system-manage/node_modules/.pnpm/@vue+runtime-core@3.4.27/node_modules/@vue/runtime-core/dist/runtime-core.esm-bundler.js:1761)
scheduler (/Users/yft/work/ksc-system-manage/node_modules/.pnpm/@vue+runtime-core@3.4.27/node_modules/@vue/runtime-core/dist/runtime-core.esm-bundler.js:1972)
resetScheduling (/Users/yft/work/ksc-system-manage/node_modules/.pnpm/@vue+reactivity@3.4.27/node_modules/@vue/reactivity/dist/reactivity.esm-bundler.js:263)
triggerEffects (/Users/yft/work/ksc-system-manage/node_modules/.pnpm/@vue+reactivity@3.4.27/node_modules/@vue/reactivity/dist/reactivity.esm-bundler.js:307)
triggerRefValue (/Users/yft/work/ksc-system-manage/node_modules/.pnpm/@vue+reactivity@3.4.27/node_modules/@vue/reactivity/dist/reactivity.esm-bundler.js:1069)
set value (/Users/yft/work/ksc-system-manage/node_modules/.pnpm/@vue+reactivity@3.4.27/node_modules/@vue/reactivity/dist/reactivity.esm-bundler.js:1114)
finalizeNavigation (/Users/yft/work/ksc-system-manage/node_modules/.pnpm/vue-router@4.3.2_vue@3.4.27/node_modules/vue-router/dist/vue-router.mjs:3400)
<anonymous> (/Users/yft/work/ksc-system-manage/node_modules/.pnpm/vue-router@4.3.2_vue@3.4.27/node_modules/vue-router/dist/vue-router.mjs:3265)
Promise.then (未知源:0)
pushWithRedirect (/Users/yft/work/ksc-system-manage/node_modules/.pnpm/vue-router@4.3.2_vue@3.4.27/node_modules/vue-router/dist/vue-router.mjs:3232)
push (/Users/yft/work/ksc-system-manage/node_modules/.pnpm/vue-router@4.3.2_vue@3.4.27/node_modules/vue-router/dist/vue-router.mjs:3157)

xiezuo20240903-110859
xiezuo20240903-110946

Validations

@btea
Copy link
Collaborator

btea commented Sep 3, 2024

You can directly start the debug terminal, then start the project normally, the code should stop at your breakpoint.

image

@qinfeng0214
Copy link
Author

You can directly start the debug terminal, then start the project normally, the code should stop at your breakpoint.

image

Thanks, it's not a vite issue, maybe it's a dependency issue

@github-actions github-actions bot locked and limited conversation to collaborators Sep 21, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants