vbenjs / vite-plugin-mock

A mock plugin for vite.use mockjs.
MIT License
621 stars 96 forks source link

无法正常使用 #20

Closed rainbox-taojun closed 3 years ago

rainbox-taojun commented 3 years ago

vite.config.js:

// import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import vueJsx from '@vitejs/plugin-vue-jsx'
import { resolve } from 'path'
import { viteMockServe } from 'vite-plugin-mock'

// https://vitejs.dev/config/
export default ({command}) => {
  let prodMock = true

  return {
    plugins: [
      vue(),
      vueJsx(),
      viteMockServe({
        supportTs: false,
        // default
        mockPath: 'mock',
        localEnabled: command === 'serve',
        prodEnabled: command !== 'serve' && prodMock,
        injectCode: `
            import { setupProdMockServer } from './mock/mock-server';
            setupProdMockServer();
          `,
      })
    ],
    resolve: {
      alias: {
        '@': resolve(__dirname, './src')
      }
    }
  }
}
(node:14128) UnhandledPromiseRejectionWarning: TypeError: Unexpected MODIFIER at 29, expected END
    at mustConsume (D:\Web Program\vue3-admin-template\node_modules\path-to-regexp\dist\index.js:114:15)        
    at parse (D:\Web Program\vue3-admin-template\node_modules\path-to-regexp\dist\index.js:173:9)
    at stringToRegexp (D:\Web Program\vue3-admin-template\node_modules\path-to-regexp\dist\index.js:331:27)     
    at pathToRegexp (D:\Web Program\vue3-admin-template\node_modules\path-to-regexp\dist\index.js:405:12)       
    at D:\Web Program\vue3-admin-template\node_modules\vite-plugin-mock\dist\index.js:86:41
    at Array.find (<anonymous>)
    at middleware (D:\Web Program\vue3-admin-template\node_modules\vite-plugin-mock\dist\index.js:79:35)        
    at call (D:\Web Program\vue3-admin-template\node_modules\vite\dist\node\chunks\dep-66eb515d.js:49422:7)     
    at next (D:\Web Program\vue3-admin-template\node_modules\vite\dist\node\chunks\dep-66eb515d.js:49366:5)     
    at Function.handle (D:\Web Program\vue3-admin-template\node_modules\vite\dist\node\chunks\dep-66eb515d.js:49369:3)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:14128) 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:14128) [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.
xiaoxian521 commented 3 years ago

提供一个仓库链接吧 帮你调试一下

rainbox-taojun commented 3 years ago

提供一个仓库链接吧 帮你调试一下

不好意思来晚了,这个是地址,不胜感激。 https://github.com/rainbox-taojun/vue3-template/tree/mock

xiaoxian521 commented 3 years ago

@rainbox-taojun 我运行了vite-plugin-mock下的example下的js例子 并没有报错 估计是和你项目中某些东西冲突了 我再看看

xiaoxian521 commented 3 years ago

@rainbox-taojun 找到原因了,你项目mock文件夹下的js写法有问题,把type换成method,并且response返回的参数写法也有问题哦,参考vite-plugin-mock下的example下的js例子写法

rainbox-taojun commented 3 years ago

@rainbox-taojun 找到原因了,你项目mock文件夹下的js写法有问题,把type换成method,并且response返回的参数写法也有问题哦,参考vite-plugin-mock下的example下的js例子写法

谢谢了

xiaoxian521 commented 3 years ago

嗯嗯 关了这个issues吧