question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Help] How to use vite to svelte build?

See original GitHub issue

Describe the bug

I want to combine svelte and vite, their performance is so amazing, but when I run yarn build, I encountered some errors.

Reproduction

this is my vite.config.ts:

import { defineConfig } from 'vite'
import svelte from 'rollup-plugin-svelte-hot'
import sveltePreprocess from 'svelte-preprocess'

// https://vitejs.dev/config/
export default defineConfig({
	plugins: [
		svelte({
			preprocess: sveltePreprocess()
		})
	]
})

this is my script:

"scripts": {
    "dev": "vite",
    "build": "vite build",
    "serve": "vite preview",
    "format": "prettier --write \"./**/*.ts\" \"./**/*.svelte\" "
  },

when I run yarn build ,I get these error info:

$ vite build
building for production...
[svelte-preprocess] The file  "/src/main.ts" was not found.
[svelte] Cannot find module './transformers/module'
.....

detail info in Logs👇

And this my repository : https://github.com/xieyezi/vite-vue3-react-svelte-todo-app/tree/main/packages/svelte-todo

System Info

  • vite version: ^2.0.0-beta.50
  • Operating System: Mac Os Catalina 10.15.7
  • Node version: v15.2.1
  • Package manager (npm/yarn/pnpm) and version: yarn 1.22.10

Logs

yarn run v1.22.10
$ vite build --debug
  vite:config bundled config file loaded in 109ms +0ms
  vite:config using resolved config: {
  vite:config   plugins: [
  vite:config     'alias',
  vite:config     'vite:dynamic-import-polyfill',
  vite:config     'vite:resolve',
  vite:config     'vite:html',
  vite:config     'vite:css',
  vite:config     'vite:esbuild',
  vite:config     'vite:json',
  vite:config     'vite:wasm',
  vite:config     'vite:worker',
  vite:config     'vite:asset',
  vite:config     'svelte',
  vite:config     'vite:css-post',
  vite:config     'vite:build-html',
  vite:config     'commonjs',
  vite:config     'vite:data-uri',
  vite:config     'vite:define',
  vite:config     'rollup-plugin-dynamic-import-variables',
  vite:config     'vite:import-analysis',
  vite:config     'vite:esbuild-transpile',
  vite:config     'vite:terser',
  vite:config     'vite:size'
  vite:config   ],
  vite:config   build: {
  vite:config     target: [ 'es2019', 'edge16', 'firefox60', 'chrome61', 'safari11' ],
  vite:config     polyfillDynamicImport: true,
  vite:config     outDir: 'dist',
  vite:config     assetsDir: 'assets',
  vite:config     assetsInlineLimit: 4096,
  vite:config     cssCodeSplit: true,
  vite:config     sourcemap: false,
  vite:config     rollupOptions: {},
  vite:config     commonjsOptions: { include: [Array], extensions: [Array] },
  vite:config     minify: 'terser',
  vite:config     terserOptions: {},
  vite:config     cleanCssOptions: {},
  vite:config     write: true,
  vite:config     emptyOutDir: null,
  vite:config     manifest: false,
  vite:config     lib: false,
  vite:config     ssr: false,
  vite:config     ssrManifest: false
  vite:config   },
  vite:config   configFile: '/Users/xieyezi/myself/vite-vue3-react-svelte-todo/packages/svelte-todo/vite.config.ts',
  vite:config   inlineConfig: {
  vite:config     root: undefined,
  vite:config     base: undefined,
  vite:config     mode: undefined,
  vite:config     configFile: undefined,
  vite:config     logLevel: undefined,
  vite:config     clearScreen: undefined,
  vite:config     build: {}
  vite:config   },
  vite:config   root: '/Users/xieyezi/myself/vite-vue3-react-svelte-todo/packages/svelte-todo',
  vite:config   command: 'build',
  vite:config   mode: 'production',
  vite:config   isProduction: true,
  vite:config   optimizeCacheDir: '/Users/xieyezi/myself/vite-vue3-react-svelte-todo/packages/svelte-todo/node_modules/.vite',
  vite:config   alias: [
  vite:config     {
  vite:config       find: /^\/@vite\//,
  vite:config       replacement: '/Users/xieyezi/myself/vite-vue3-react-svelte-todo/node_modules/vite/dist/client/'
  vite:config     }
  vite:config   ],
  vite:config   server: {},
  vite:config   env: { BASE_URL: '/', MODE: 'production', DEV: false, PROD: true },
  vite:config   assetsInclude: [Function: assetsInclude],
  vite:config   logger: {
  vite:config     hasWarned: false,
  vite:config     info: [Function: info],
  vite:config     warn: [Function: warn],
  vite:config     error: [Function: error],
  vite:config     clearScreen: [Function: clearScreen]
  vite:config   },
  vite:config   base: '/'
  vite:config } +4ms
building for production...
[svelte-preprocess] The file  "/src/main.ts" was not found.
[svelte] Cannot find module './transformers/module'
Require stack:
- /Users/xieyezi/myself/vite-vue3-react-svelte-todo/node_modules/svelte-preprocess/dist/autoProcess.js
- /Users/xieyezi/myself/vite-vue3-react-svelte-todo/node_modules/svelte-preprocess/dist/index.js
- /Users/xieyezi/myself/vite-vue3-react-svelte-todo/packages/svelte-todo/vite.config.ts
- /Users/xieyezi/myself/vite-vue3-react-svelte-todo/node_modules/vite/dist/node/chunks/dep-19255ed7.js
- /Users/xieyezi/myself/vite-vue3-react-svelte-todo/node_modules/vite/dist/node/cli.js
- /Users/xieyezi/myself/vite-vue3-react-svelte-todo/node_modules/vite/bin/vite.js
file: /Users/xieyezi/myself/vite-vue3-react-svelte-todo/packages/svelte-todo/index.html
error during build:
Error: Cannot find module './transformers/module'
Require stack:
- /Users/xieyezi/myself/vite-vue3-react-svelte-todo/node_modules/svelte-preprocess/dist/autoProcess.js
- /Users/xieyezi/myself/vite-vue3-react-svelte-todo/node_modules/svelte-preprocess/dist/index.js
- /Users/xieyezi/myself/vite-vue3-react-svelte-todo/packages/svelte-todo/vite.config.ts
- /Users/xieyezi/myself/vite-vue3-react-svelte-todo/node_modules/vite/dist/node/chunks/dep-19255ed7.js
- /Users/xieyezi/myself/vite-vue3-react-svelte-todo/node_modules/vite/dist/node/cli.js
- /Users/xieyezi/myself/vite-vue3-react-svelte-todo/node_modules/vite/bin/vite.js
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:919:15)
    at Function.Module._load (node:internal/modules/cjs/loader:763:27)
    at Module.require (node:internal/modules/cjs/loader:991:19)
    at require (node:internal/modules/cjs/helpers:92:18)
    at /Users/xieyezi/myself/vite-vue3-react-svelte-todo/node_modules/svelte-preprocess/dist/autoProcess.js:36:77
    at async Object.exports.transform (/Users/xieyezi/myself/vite-vue3-react-svelte-todo/node_modules/svelte-preprocess/dist/autoProcess.js:36:29)
    at async /Users/xieyezi/myself/vite-vue3-react-svelte-todo/node_modules/svelte-preprocess/dist/autoProcess.js:96:29
    at async script (/Users/xieyezi/myself/vite-vue3-react-svelte-todo/node_modules/svelte-preprocess/dist/autoProcess.js:124:33)
    at async process_single_tag (/Users/xieyezi/myself/vite-vue3-react-svelte-todo/node_modules/svelte/compiler.js:28953:28)
    at async Promise.all (index 0)
error Command failed with exit code 1.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

5reactions
xieyezicommented, Feb 5, 2021

@JVictorV I just have try vite-plugin-svelte too, it was great,thanks!What surprised me more was that it’s supported SSR already!

3reactions
JVictorVcommented, Feb 5, 2021

@xieyezi I just tried to set it up with @benmccann vite-plugin-svelte, works like a charm!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Making a simple note app using Svelte and Vite - Medium
In this article, I will explain how to create a simple note app using Svelte and Vite for those interested in trying them...
Read more >
Getting Started - Vite
Trying Vite Online # ... You can try Vite online on StackBlitz. It runs the Vite-based build setup directly in the browser, so...
Read more >
Build and Deploy apps with Svelte and Vite - Eternal Dev
Vite is known as Next Generation Frontend Tooling System in its documentation. It means that it helps in building and creating a good...
Read more >
Svelte.js 3 & The Vite Build Tool Tutorial - KoderHQ
1. If it's your first time using Vite, it will ask you to install an additional package. · 2. Next, choose a name...
Read more >
How to Set up Svelte using Vite, TypeScript and Tailwind CSS
Setting up the application with Vite and TypeScript · Enter your preferred application name as svelte-app . · Select svelte as your desired ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found