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.

[vite] Internal server error: Failed to resolve import "stui-vue" from "src/markdown/get-started.md". Does the file exist?

See original GitHub issue

What configuration is missing?

Describe the bug

vite upgrade 1.0.0-rc.1 to 2.5.10 Step1:yarn add vite@2.5.10 Step2:yarn dev error:

[vite] Internal server error: Failed to resolve import "stui-vue" from "src/markdown/get-started.md". Does the file exist?
  Plugin: vite:import-analysis
  File: /Users/erica/Desktop/01前端/05项目/06goal-Vue3-wheel/src/markdown/get-started.md
  1  |  
  2  |  import {Button, Tabs, Tab, Switch, Dialog, openDialog} from "stui-vue"
     |                                                               ^
  3  |  const _sfc_main = {
  4  |    components: {Button}
      at formatError (/Users/erica/Desktop/01前端/05项目/06goal-Vue3-wheel/node_modules/vite/dist/node/chunks/dep-36bf480c.js:50163:46)
      at TransformContext.error (/Users/erica/Desktop/01前端/05项目/06goal-Vue3-wheel/node_modules/vite/dist/node/chunks/dep-36bf480c.js:50159:19)
      at normalizeUrl (/Users/erica/Desktop/01前端/05项目/06goal-Vue3-wheel/node_modules/vite/dist/node/chunks/dep-36bf480c.js:75881:26)
      at async TransformContext.transform (/Users/erica/Desktop/01前端/05项目/06goal-Vue3-wheel/node_modules/vite/dist/node/chunks/dep-36bf480c.js:76016:57)
      at async Object.transform (/Users/erica/Desktop/01前端/05项目/06goal-Vue3-wheel/node_modules/vite/dist/node/chunks/dep-36bf480c.js:50373:30)
      at async transformRequest (/Users/erica/Desktop/01前端/05项目/06goal-Vue3-wheel/node_modules/vite/dist/node/chunks/dep-36bf480c.js:65414:29)
      at async viteTransformMiddleware (/Users/erica/Desktop/01前端/05项目/06goal-Vue3-wheel/node_modules/vite/dist/node/chunks/dep-36bf480c.js:65542:32)

package.json

  "scripts": {
    "dev": "vite",
    "build": "vite build"
  },
  "resolutions": {
    "node-sass": "npm:sass@1.26.11"
  },
  "dependencies": {
    "@vitejs/plugin-vue": "^1.4.0",
    "esbuild": "^0.6.0",
    "github-markdown-css": "4.0.0",
    "marked": "1.1.1",
    "prismjs": "1.21.0",
    "rollup": "^2.0.0",
    "vue": "3.0.0",
    "vue-router": "4.0.0-beta.3"
  },
  "devDependencies": {
    "@vue/compiler-sfc": "3.0.0",
    "rollup-plugin-esbuild": "2.5.0",
    "rollup-plugin-scss": "2.6.0",
    "rollup-plugin-terser": "7.0.2",
    "rollup-plugin-vue": "6.0.0-beta.10",
    "sass": "1.32.11",
    "vite": "2.5.10",
    "vite-plugin-html": "^3.2.0",
    "vite-plugin-markdown": "^2.0.2",
    "vite-plugin-vue": "^0.0.0"
  }

vite.config.ts

import { md } from "./plugins/vite-plugin-md";
import fs from 'fs'
import {baseParse} from '@vue/compiler-core'
import {defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'

export default defineConfig({
  base: './',
  assetsDir: 'assets',
  plugins: [
    md(), 
    vue({ include: [/\.vue$/, /\.md$/]}),
  ],
  vueCustomBlockTransforms: {
    demo: (options) => {
      const { path } = options
      const file = fs.readFileSync(path).toString()
      const parsed = baseParse(file).children.find(n => n.tag === 'demo')
      const title = parsed.children[0].content
      const main = file.split(parsed.loc.source).join('').trim()
      return `export default function (Component) {
        Component.__sourceCode = ${JSON.stringify(main)}
        Component.__sourceCodeTitle = ${JSON.stringify(title)}
      }`.trim()
    }
  }
});

vite-plugin-md.ts file type ‘.md’ to ‘.js’

import path from 'path'
import fs from 'fs'
import marked from 'marked'

const mdToJs = str => {
  const content = JSON.stringify(marked(str))
  return `export default ${content}`
}

export function md() {
  return {
    name: 'md', 
    configureServer(){ // 用于开发
      async ({ app }) => {
        app.use(async (ctx, next) => { // koa
          if (ctx.path.endsWith('.md')) {
            ctx.type = 'js'
            const filePath = path.join(process.cwd(), ctx.path)
            ctx.body = mdToJs(fs.readFileSync(filePath).toString())
          } else {
            await next()
          }
        })
      }
    },
    transform(code, id){ // 用于 rollup // 插件
      // 获取.md文件
      const fileArr = id.split('.') //根据.分割数组
      const fileType = fileArr[fileArr.length -1]; //取最后一个
      if(fileType === 'md'){
        mdToJs(code) 
      }
    }
  }
}

What configuration is missing?

Reproduction

https://github.com/ericasun/goal-Vue3-wheel-code

System Info

System:
    OS: Mac
  Binaries:
    Node: 14.18.3  - /usr/local/bin/node
    Yarn: 1.22.10 - /usr/local/bin/yarn
    npm: 6.14.15 - /usr/local/bin/npm
  Browsers:
    chorme: 102.0.5005.115
  npmPackages:
     Vite: 1.0.0-rc.1 => 2.5.10

Used Package Manager

yarn

Logs

i try to add it to build.rollupOptions.external, but it’s useless.

[vite]: Rollup failed to resolve import "stui-vue" from "src/markdown/get-started.md".
This is most likely unintended because it can break your application at runtime.
If you do want to externalize this module explicitly add it to
`build.rollupOptions.external`
error during build:
Error: [vite]: Rollup failed to resolve import "stui-vue" from "src/markdown/get-started.md".
This is most likely unintended because it can break your application at runtime.
If you do want to externalize this module explicitly add it to
`build.rollupOptions.external`
    at onRollupWarning (/Users/erica/Desktop/01前端/05项目/06goal-Vue3-wheel/node_modules/vite/dist/node/chunks/dep-36bf480c.js:51210:19)
    at onwarn (/Users/erica/Desktop/01前端/05项目/06goal-Vue3-wheel/node_modules/vite/dist/node/chunks/dep-36bf480c.js:50994:13)
    at Object.onwarn (/Users/erica/Desktop/01前端/05项目/06goal-Vue3-wheel/node_modules/rollup/dist/shared/rollup.js:23215:13)
    at ModuleLoader.handleResolveId (/Users/erica/Desktop/01前端/05项目/06goal-Vue3-wheel/node_modules/rollup/dist/shared/rollup.js:22465:26)
    at /Users/erica/Desktop/01前端/05项目/06goal-Vue3-wheel/node_modules/rollup/dist/shared/rollup.js:22426:26

Validations

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
ericasuncommented, Jul 25, 2022

@ericasun Your reproduction shows 404.

it’s ok now

0reactions
ericasuncommented, Jul 25, 2022

3.0.2

Oh, sorry for that. I upgraded to vite 3.0.2, plugin-vue 3.0.1, Vue 3.2.37.

I upgraded according to your prompt, but still showed this error

What else did I miss?

Read more comments on GitHub >

github_iconTop Results From Across the Web

[vite] Internal server error: Failed to resolve import "stui-vue ...
[vite] Internal server error: Failed to resolve import "stui-vue" from "src/markdown/get-started.md". Does the file exist?
Read more >
[vite] internal server error: failed to resolve import
vitejs/vite[vite] Internal server error: Failed to resolve import "stui-vue" from "src/markdown/get-started.md". Does the file exist?#9351.
Read more >
Ask Question
Internal server error : Failed to resolve import "./store" from "src\main.ts". Does the file exist? The code is: import store from "./store";.
Read more >
Internal Server Error when trying to import my ,com file to .org
I have learnt from a DreamHost agent that i cannot promote my .com site through another domain, but i guess i can still...
Read more >
Error when importing a component / layout
[plugin:vite:import-analysis] Failed to resolve import ". ... Does the file exist? ... in Single File Components, to point to the Laravel web //...
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