内部服务器错误:无法读取未定义的属性“长度”

Swa*_*nil 7 vue.js vite

出现错误

[vite] 内部服务器错误:无法读取未定义的属性“长度”

这是在尝试使用 vite 运行我的 vue 项目时发生的。

下面是错误堆栈:

构建失败,出现 1 个错误:node_modules/vite/dist/node/chunks/dep-27bc1ab8.js:59574:34: 错误: [插件: vite:dep-scan] 无法读取未定义 2:44:29 的属性“长度” PM [vite] 内部服务器错误:无法读取匹配处未定义的属性“长度”(/Users/pandocorp/Desktop/pando/codes/pando-app/frontend/shipper/node_modules/vite/dist/node/chunks/dep- 27bc1ab8.js:59574:35) 在 /Users/pandocorp/Desktop/pando/codes/pando-app/frontend/shipper/node_modules/vite/dist/node/chunks/dep-27bc1ab8.js:59633:58 在数组。 find () 在 Context.resolveId (/Users/pandocorp/Desktop/pando/codes/pando-app/frontend/shipper/node_modules/vite/dist/node/chunks/dep-27bc1ab8.js:59633:42) 处的对象。在 processTicksAndRejections (internal/process/task_queues. js:95:5) 在异步 ModuleGraph.resolveUrl (/Users/pandocorp/Desktop/pando/codes/pando-app/frontend/shipper/node_modules/vite/dist/node/chunks/dep-27bc1ab8.js:56244:26 )在异步 ModuleGraph.getModuleByUrl (/Users/pandocorp/Desktop/pando/codes/pando-app/frontend/shipper/node_modules/vite/dist/node/chunks/dep-27bc1ab8.js:56124:23)在异步 doTransform ( /Users/pandocorp/Desktop/pando/codes/pando-app/frontend/shipper/node_modules/vite/dist/node/chunks/dep-27bc1ab8.js:55582:20)

我的 vite.config.js

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

const config = require('./config');
const path = require('path');

export default defineConfig({
plugins: [createVuePlugin()],
server: {
port: 8080,
},
resolve: {
alias: [
{
'@': path.resolve(__dirname, './src'),
},
{
'@common': path.resolve(__dirname, '../common-v2'),
},
// {
// find: path.resolve(__dirname, '../static'),
// replacement: config.dev.assetsSubDirectory,
// ignore: ['.'],
// },
// {
// find: path.resolve(__dirname, '../firebase-messaging-sw.js'),
// replacement: 'firebase-messaging-sw.js',
// ignore: ['.'],
// },
],
},
build: {
chunkSizeWarningLimit: 600,
cssCodeSplit: false,
},
});
Run Code Online (Sandbox Code Playgroud)

小智 1

当我遇到这个错误时,添加以下内容似乎vite.config.js可以解决它。

resolve: {
    alias: [
        {
            find: /^~(.*)$/,
            replacement: 'node_modules/$1',
        },
    ],
},
Run Code Online (Sandbox Code Playgroud)