英文:
Can not resolve Vite html loader file error
问题
I am using vite for a project, but when I run npm run dev
I get the error
Failed to scan for dependencies from entries: <path>/Learning/Vite-test/index.html
[ERROR] No loader is configured for ".html" files: index.html
I do not know what may be causing the error (and it seems either new or specific to my case) as I am still learning and do not seem to find any issue related through search.
我正在使用 Vite 进行项目开发,但当我运行 npm run dev
时,我遇到了以下错误:
从条目扫描依赖项失败:
<path>/Learning/Vite-test/index.html
[ERROR] 未为 ".html" 文件配置任何加载器: index.html
我不知道是什么导致了这个错误(而且它似乎是新的或特定于我的情况),因为我还在学习,而且似乎无法通过搜索找到任何相关的问题。
I tried installing html loader
and adding it to the vite configuration file but it did not change anything.
我尝试安装了 html loader
并将其添加到 Vite 配置文件中,但没有改变任何事情。
The following is my vite configuration file:
以下是我的 Vite 配置文件:
import { fileURLToPath, URL } from 'node:url'
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
// https://vitejs.dev/config/
export default defineConfig({
plugins: [
vue(),
],
resolve: {
alias: {
'@': fileURLToPath(new URL('./src', import.meta.url))
},
resolve: {
extensions: ['.js', '.ts', '.vue', '.json', '.html'],
},
module: {
rules: [
{
test: /\.html$/i,
loader: 'html-loader',
},
],
},
}
})
I also get a similar error when creating projects with Vue/cli which is:
当使用 Vue/cli 创建项目时,我也遇到了类似的错误:
Compiling...
ERROR Failed to compile with 1 error 8:24:19 PM
error
Module not found: Error: Can't resolve '<path>\learn-vuetify\node_modules\webpack-dev-server\client\index.js?protocol=ws&hostname=192.168.8.106&port=8080&pathname=%2Fws&logging=none&progress=true&overlay=%7B%22errors%22%3Atrue%2C%22warnings%22%3Afalse%7D&reconnect=10&hot=true&live-reload=true' in '<path>\learn-vuetify'
ERROR in Module not found: Error: Can't resolve '<path>\learn-vuetify\node_modules\webpack-dev-server\client\index.js?protocol=ws&hostname=192.168.8.106&port=8080&pathname=%2Fws&logging=none&progress=true&overlay=%7B%22errors%22%3Atrue%2C%22warnings%22%3Afalse%7D&reconnect=10&hot=true&live-reload=true' in '<path>\learn-vuetify'
webpack compiled with 1 error
我有一些想法:
- 与 Windows 中的某些本地安全选项相关
- 安装 Node.js 时出现问题
- 依赖项损坏(可能有人遇到了同样的错误,但没有人遇到 - 稀有情况)。
我不知道具体原因... 请帮忙排查!
英文:
I am using vite for a project, but when I run npm run dev
I get the error
Failed to scan for dependencies from entries:
<path>/Learning/Vite-test/index.html
[ERROR] No loader is configured for ".html" files: index.html
I do not know what may be causing the error (and it seems either new or specific to my case) as I am still learning and do not seem to find any issue related through search.
I tried installing html loader
and adding it to the vite configuration file but it did not change anything.
The following is my vite configuration file:
import { fileURLToPath, URL } from 'node:url'
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
// https://vitejs.dev/config/
export default defineConfig({
plugins: [
vue(),
],
resolve: {
alias: {
'@': fileURLToPath(new URL('./src', import.meta.url))
},
resolve: {
extensions: ['.js', '.ts', '.vue', '.json', '.html'],
},
module: {
rules: [
{
test: /\.html$/i,
loader: 'html-loader',
},
],
},
}
})
I also get a similar error when creating projects with Vue/cli which is:
Compiling...
ERROR Failed to compile with 1 error 8:24:19 PM
error
Module not found: Error: Can't resolve '<path>\learn-vuetify\node_modules\webpack-dev-server\client\index.js?protocol=ws&hostname=192.168.8.106&port=8080&pathname=%2Fws&logging=none&progress=true&overlay=%7B%22errors%22%3Atrue%2C%22warnings%22%3Afalse%7D&reconnect=10&hot=true&live-reload=true' in '<path>\learn-vuetify'
ERROR in Module not found: Error: Can't resolve '<path>\learn-vuetify\node_modules\webpack-dev-server\client\index.js?protocol=ws&hostname=192.168.8.106&port=8080&pathname=%2Fws&logging=none&progress=true&overlay=%7B%22errors%22%3Atrue%2C%22warnings%22%3Afalse%7D&reconnect=10&hot=true&live-reload=true' in '<path>\learn-vuetify'
webpack compiled with 1 error
I have some ideas in mind:
- Related and caused by some local security option in windows
- Something went wrong when installing node
- Corrupt dependencies (someone could have had the same error, but no one did - rare).
I have no idea for the cause ... please help!!!
答案1
得分: 1
问题出在本地,如预期的那样!问题是路径太长且包含空格,所以不要使用:
D:/folder/sub folder/ 1 sub folder/ another_subfolder/some-more/myProject
而要使用:
D:/folder/sub_folder/myProject
祝大家好运。
英文:
The problem was local as expected!!
It was that the path was too long and containing spaces, so instead of using:
D:/folder/sub folder/ 1 sub folder/ another_subfolder/some-more/myProject
Use:
D:/folder/sub_folder/myProject
Good Luck everyone.
答案2
得分: 1
我遇到了相同的错误,问题出在路径上。
我的路径是:
E:\#Development\MERN\R\First-app
路径中的 #
导致了问题。
现在对我来说已经正常工作了。
新路径:
E:\Development\MERN\R\First-app
英文:
I encountered same error and the problem was with the path
My Path was:
E:\#Development\MERN\R\First-app
This #
in the path was causing the issue.
well it works fine for me now.
New Path:
E:\Development\MERN\R\First-app
答案3
得分: 0
我遇到了相同的问题。我不得不卸载了我的电脑上的防病毒软件(Smadav)。
英文:
I encountered the same problem. I had to uninstall the anti-virus(Smadav) on my computer.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论