vitePluginString 不是函数

San*_*nth 3 svelte vite

创建了一个 vite + svelte

\n
$ npm init vite@latest\n\xe2\x9c\x94 Project name: \xe2\x80\xa6 app1\n\xe2\x9c\x94 Select a framework: \xe2\x80\xba svelte\n\xe2\x9c\x94 Select a variant: \xe2\x80\xba svelte-ts\n
Run Code Online (Sandbox Code Playgroud)\n

想要包含vite-plugin-string来使用glsl文件

\n

已安装

\n

npm install --save-dev vite-plugin-string

\n

配置vite.config.js文件如下

\n
$ npm init vite@latest\n\xe2\x9c\x94 Project name: \xe2\x80\xa6 app1\n\xe2\x9c\x94 Select a framework: \xe2\x80\xba svelte\n\xe2\x9c\x94 Select a variant: \xe2\x80\xba svelte-ts\n
Run Code Online (Sandbox Code Playgroud)\n

只要跑起来npm run dev

\n

我收到这个错误

\n
> app1@0.0.0 dev\n> vite\n\nfailed to load config from ....../Six/trailRun/vite.config.js\nerror when starting dev server:\nTypeError: vitePluginString is not a function\n    at file:///....../Six/trailRun/vite.config.js?t=1642958252054:8:22\n    at ModuleJob.run (node:internal/modules/esm/module_job:195:25)\n    at async Promise.all (index 0)\n    at async ESMLoader.import (node:internal/modules/esm/loader:337:24)\n    at async importModuleDynamicallyWrapper (node:internal/vm/module:437:15)\n    at async loadConfigFromFile (/....../Six/trailRun/node_modules/vite/dist/node/chunks/dep-f5552faa.js:75089:31)\n    at async resolveConfig (/....../Six/trailRun/node_modules/vite/dist/node/chunks/dep-f5552faa.js:74656:28)\n    at async createServer (/....../Six/trailRun/node_modules/vite/dist/node/chunks/dep-f5552faa.js:60326:20)\n    at async CAC.<anonymous> (/....../Six/trailRun/node_modules/vite/dist/node/cli.js:688:24)\n\n
Run Code Online (Sandbox Code Playgroud)\n

我需要做出哪些改变来纠正这个问题?

\n

ton*_*y19 11

该模块实际上在属性中导出插件函数default

// vite.config.js
import { defineConfig } from 'vite'
import { svelte } from '@sveltejs/vite-plugin-svelte'
import vitePluginString from 'vite-plugin-string'

export default defineConfig({
  plugins: [
    svelte(),
    vitePluginString.default(), 
  ],
})
Run Code Online (Sandbox Code Playgroud)

演示

  • 我有几个 Vite 插件,这似乎是一个问题,但它们都将其用法记录为_不需要_需要“.default”。似乎存在更深层次的问题,因为很明显这不是预期的用法。 (2认同)