Vite seems to be looking in node_modules? - Stack Overflow

admin2025-04-17  2

Trying to spin up a Vite dev server and an error that I'm receiving seems to indicate that it's looking in node_modules when it should be ignored by default.

Here is my vite.config.ts

import { defineConfig } from 'vite'
import { VitePluginNode } from 'vite-plugin-node'
import babel from 'vite-plugin-babel';
import commonjs from 'vite-plugin-commonjs'
import path from 'path'

export default defineConfig({
    server: {
        port: 3001,
    },
    build: {
        target: 'esnext',
        commonjsOptions: { transformMixedEsModules: true }
    },
    resolve: {
        alias: {
            // aliases here
        },
    },
    plugins: [
        commonjs(), // Transform commonJS to ES Modules
        babel(),
        ...VitePluginNode({
            adapter: 'express',
            appPath: 'some/path/server', // Path to entry file
            exportName: 'app', // Name of the exported express app
            tsCompiler: 'esbuild', // Compiler to use
            swcOptions: {},
        }),
    ],
})

The error I'm getting is:

[vite] (ssr) Error when evaluating SSR module some/path/server:
|- Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/path/to/project/node_modules/@org/another/path/FinalComponent' imported from /path/to/project/node_modules/@org/another/path/lib/bundles/blah.min/index.js
Did you mean to import "@org/another/path/FinalComponent"?

You'll notice that Vite complains about files and imports that are in node_modules. Why is this and how do I resolve this?

转载请注明原文地址:http://anycun.com/QandA/1744847450a88452.html