Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

引入外部文件报错Uncaught SyntaxError: The requested module '/@modules/vue.js' does not provide an export named 'default' #891

Closed
laijinxian opened this issue Oct 10, 2020 · 8 comments

Comments

@laijinxian
Copy link

我在router/index.ts 文件下引入 外包文件 global.ts; 运行报错 **Uncaught SyntaxError: The requested module '/@modules/vue.js' does not provide an export named 'default**

我在vue2.x 项目中一直是这样用的没问题,但在vue3 + vite 下 就报错了;

image

router/index.ts

import {createRouter, createWebHashHistory} from'vue-router'

import { vueRouters } from '../utils/global'

// 在 Vue-router新版本中,需要使用createRouter来创建路由
export default createRouter({
  // 指定路由的模式,此处使用的是hash模式
  history: createWebHashHistory(),
  routes: [
    ...vueRouters()
  ]
})

global.ts

...
export const vueRouters = () => {
  // todo
}
...
@underfin
Copy link
Member

Can you give a reproduction ?

@laijinxian
Copy link
Author

Copy what?

@underfin
Copy link
Member

Please provide a link to a repo that can reproduce the problem you ran into.

A reproduction is required unless you are absolutely sure that the the problem is obvious and the information you provided is enough for us to understand what the problem is. If a report has only vague description (e.g. just a generic error message) and has no reproduction, it will be closed immediately.

@skillnull
Copy link

我也遇到了同样的问题,引用echarts报错:

import Echarts from 'echarts'

image
Uncaught SyntaxError: The requested module '/@modules/echarts/index.js' does not provide an export named 'default'

@WJCHumble
Copy link

WJCHumble commented Nov 5, 2020

@skillnull 这个应该是因为 vite 只支持 es6 module ,不支持 common.js 的原因,可以看一下这个 pr #837

@Hjw52
Copy link

Hjw52 commented Apr 11, 2021

你好 我想问下解决方法是配置 optimizeDeps:{include:[]}吗?vue-class-component一直不支持不知道为什么

@happy-func
Copy link

happy-func commented Jun 2, 2021

你好 我想问下解决方法是配置 optimizeDeps:{include:[]}吗?vue-class-component一直不支持不知道为什么

import { createRouter, createWebHashHistory } from "vue-router";

import {
    BASE_ROUTE,
} from "@/router/routes.ts";

const router = createRouter({
  end: false,
  history: createWebHashHistory(),
  sensitive: false,
  strict: false,
  routes: BASE_ROUTE
});

export default router;

use like this

@github-actions
Copy link

This issue has been locked since it has been closed for more than 14 days.

If you have found a concrete bug or regression related to it, please open a new bug report with a reproduction against the latest Vite version. If you have any other comments you should join the chat at Vite Land or create a new discussion.

@github-actions github-actions bot locked and limited conversation to collaborators Jul 16, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

6 participants