Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
853 views
in Technique[技术] by (71.8m points)

有用过vite的吗

通过用了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',
    'x00x00node-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

求助大佬


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神解答

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...