有用过vite的吗

发布于 2022-09-12 13:09:49 字数 5707 浏览 20 评论 0

通过用了vite的插件让vite能跑vue2
但是发现好像当代码中 有非esm规范的可能浏览器就解析不了了,查了一下,说optimization这个配置启动的话是能自动转的,将cjs转成esm规范,但是不知道为什么一直跑不起来,报这个错

[vite] Dep optimization failed with error:
The argument 'path' must be a string or Uint8Array without null bytes. Received '/Users/dev/Documents/project/test/test-vite/\x00/Users/dev/Documents/project/test/test-vite/node_modules/xlsx/pac...
TypeError [ERR_INVALID_ARG_VALUE]: The argument 'path' must be a string or Uint8Array without null bytes. Received '/Users/dev/Documents/project/test/test-vite/\x00/Users/dev/Documents/project/test/test-vite/node_modules/xlsx/pac...
    at Object.statSync (fs.js:1031:10)
    at fileMtime (/Users/dev/Documents/project/test/test-vite/node_modules/@babel/core/lib/config/files/utils.js:42:28)
    at /Users/dev/Documents/project/test/test-vite/node_modules/@babel/core/lib/config/files/utils.js:30:43
    at CacheConfigurator.using (/Users/dev/Documents/project/test/test-vite/node_modules/@babel/core/lib/config/caching.js:236:17)
    at CacheConfigurator.invalidate (/Users/dev/Documents/project/test/test-vite/node_modules/@babel/core/lib/config/caching.js:254:17)
    at /Users/dev/Documents/project/test/test-vite/node_modules/@babel/core/lib/config/files/utils.js:30:26
    at Generator.next (<anonymous>)
    at Function.<anonymous> (/Users/dev/Documents/project/test/test-vite/node_modules/@babel/core/lib/gensync-utils/async.js:26:3)
    at Generator.next (<anonymous>)
    at evaluateSync (/Users/dev/Documents/project/test/test-vite/node_modules/gensync/index.js:251:28)
    at Function.sync (/Users/dev/Documents/project/test/test-vite/node_modules/gensync/index.js:89:14)
    at sync (/Users/dev/Documents/project/test/test-vite/node_modules/@babel/core/lib/gensync-utils/async.js:66:25)
    at sync (/Users/dev/Documents/project/test/test-vite/node_modules/gensync/index.js:182:19)
    at onFirstPause (/Users/dev/Documents/project/test/test-vite/node_modules/gensync/index.js:210:24)
    at Generator.next (<anonymous>)
    at cachedFunction (/Users/dev/Documents/project/test/test-vite/node_modules/@babel/core/lib/config/caching.js:68:46) {
  code: 'PLUGIN_ERROR',
  pluginCode: 'ERR_INVALID_ARG_VALUE',
  plugin: 'vite:transforms',
  hook: 'transform',
  id: '\x00/Users/dev/Documents/project/test/test-vite/node_modules/xlsx/jszip.js?commonjs-proxy',
  watchFiles: [
    '/Users/dev/Documents/project/test/test-vite/node_modules/base64-to-uint8array/index.js',
    '/Users/dev/Documents/project/test/test-vite/node_modules/ini/ini.js',
    '/Users/dev/Documents/project/test/test-vite/node_modules/raw-loader/index.js',
    '/Users/dev/Documents/project/test/test-vite/node_modules/statuses/index.js',
    '/Users/dev/Documents/project/test/test-vite/node_modules/signale/index.js',
    '/Users/dev/Documents/project/test/test-vite/node_modules/koa-bodyparser/index.js',
    '/Users/dev/Documents/project/test/test-vite/node_modules/koa-mount/index.js',
    '/Users/dev/Documents/project/test/test-vite/node_modules/koa-static/index.js',
    '/Users/dev/Documents/project/test/test-vite/node_modules/co-request/index.js',
    '/Users/dev/Documents/project/test/test-vite/node_modules/koa-webpack-hot-middleware/index.js',
    '/Users/dev/Documents/project/test/test-vite/node_modules/vuex-router-sync/index.js',
    '/Users/dev/Documents/project/test/test-vite/node_modules/xlsx/xlsx.js',
    '/Users/dev/Documents/project/test/test-vite/node_modules/badjs-report/dist/bj-report-tryjs.js',
    '/Users/dev/Documents/project/test/test-vite/node_modules/es6-promise/dist/es6-promise.js',
    '/Users/dev/Documents/project/test/test-vite/node_modules/qs/lib/index.js',
    '/Users/dev/Documents/project/test/test-vite/node_modules/js-cookie/src/js.cookie.js',
    '/Users/dev/Documents/project/test/test-vite/node_modules/koa/lib/application.js',
    '/Users/dev/Documents/project/test/test-vite/node_modules/koa-router/lib/router.js',
    '/Users/dev/Documents/project/test/test-vite/node_modules/koa-helmet/lib/koa-helmet.js',
    '/Users/dev/Documents/project/test/test-vite/node_modules/koa-webpack-dev-middleware/src/index.js',
    '\x00commonjsHelpers.js',
    '/Users/dev/Documents/project/test/test-vite/node_modules/deepmerge/dist/cjs.js',
    '\x00node-resolve:empty.js',
    '\x00\x00node-resolve:empty.js?commonjs-proxy',
    '\x00/Users/dev/Documents/project/test/test-vite/node_modules/statuses/codes.json?commonjs-proxy',
    '/Users/dev/Documents/project/test/test-vite/node_modules/statuses/codes.json',
    '/Users/dev/Documents/project/test/test-vite/node_modules/xlsx/jszip.js',
    '\x00/Users/dev/Documents/project/test/test-vite/node_modules/xlsx/jszip.js?commonjs-proxy',
    '/Users/dev/Documents/project/test/test-vite/node_modules/signale/signale.js',
    '\x00/Users/dev/Documents/project/test/test-vite/node_modules/signale/signale.js?commonjs-proxy',
    '\x00/Users/dev/Documents/project/test/test-vite/node_modules/xlsx/dist/cpexcel.js?commonjs-proxy',
    '/Users/dev/Documents/project/test/test-vite/node_modules/xlsx/dist/cpexcel.js'
  ]
}

这个是vite 的配置

import { createVuePlugin } from 'vite-plugin-vue2'

const config = {
  plugins: [createVuePlugin()],
  optimizeDeps:{
    include: ['vuex-router-sync', 'deepmerge', 'xlsx'],
    link: [],
    allowNodeBuiltins: ['koa', 'uuid', 'follow-redirects'],
    auto: true
  },
  proxy: {
    // string shorthand
    '/foo': `http://127.0.0.1:13213`,
    // with options
    '/api': {
      target: `http://127.0.0.1:13213`,
      changeOrigin: true,
      rewrite: path => path.replace(/^\/api/, '')
    }
  },

  port: 9876,
}

export default config

求助大佬

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文