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

require is not defined #162

Closed
sisisiss opened this issue Jun 20, 2021 · 1 comment
Closed

require is not defined #162

sisisiss opened this issue Jun 20, 2021 · 1 comment

Comments

@sisisiss
Copy link

sisisiss commented Jun 20, 2021

npm run vite-dev error 'require is not defined'
const modulesFiles = require.context('./modules', true, /.js$/)

@ShenQingchuan
Copy link
Member

ShenQingchuan commented Jun 22, 2021

Using vite means that you may give up those libraries which don't provide an ES Module format bundle or can't be transformed to ES Module.

参阅文档 「 依赖预构建 」

CommonJS 和 UMD 兼容性: 开发阶段中,Vite 的开发服务器将所有代码视为原生 ES 模块。因此,Vite 必须先将作为 CommonJS 或 UMD 发布的依赖项转换为 ESM。

若你使用的库及其源码本身仅提供 CommonJS 而不提供 ESM 的格式,或确认无法经过 Vite 的处理转换为 ESM,那么在 Vite 开发过程中当中将无法使用该库。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants