Vue.js - 冲突中的错误:多个资产向同一文件名index.html发出不同的内容

发布于 2025-01-12 20:37:17 字数 2384 浏览 5 评论 0原文


if I create a new vue.js project on my macbook and compile it with "npm run serve", I get the following error.
I haven't changed any file since creating it.
markus@Markuss-MBP meinerstesprojekt % npm run serve

> [email protected] serve
> vue-cli-service serve

 INFO  Starting development server...


 ERROR  Failed to compile with 1 error                                                                                                                                    6:12:51 PM

 error  

Conflict: Multiple assets emit different content to the same filename index.html

ERROR in Conflict: Multiple assets emit different content to the same filename index.html

webpack compiled with 1 error

vue.config.js

const { defineConfig } = require('@vue/cli-service')
module.exports = defineConfig({
transpileDependencies: true
})

module.exports = {
chainWebpack: (config) => {
config.resolve.symlinks(true)
}
}

package.json

{
  "name": "meinerstesprojekt",
  "version": "0.1.0",
  "private": true,
  "scripts": {
    "serve": "vue-cli-service serve",
    "build": "vue-cli-service build",
    "lint": "vue-cli-service lint"
  },
  "dependencies": {
    "core-js": "^3.8.3",
    "vue": "^2.6.14"
  },
  "devDependencies": {
    "@babel/core": "^7.12.16",
    "@babel/eslint-parser": "^7.12.16",
    "@vue/cli-plugin-babel": "~5.0.0",
    "@vue/cli-plugin-eslint": "~5.0.0",
    "@vue/cli-service": "^5.0.1",
    "eslint": "^7.32.0",
    "eslint-plugin-vue": "^8.0.3",
    "vue-template-compiler": "^2.6.14"
  },
  "eslintConfig": {
    "root": true,
    "env": {
      "node": true
    },
    "extends": [
      "plugin:vue/essential",
      "eslint:recommended"
    ],
    "parserOptions": {
      "parser": "@babel/eslint-parser"
    },
    "rules": {}
  },
  "browserslist": [
    "> 1%",
    "last 2 versions",
    "not dead"
  ]
}

npm 版本:8.5.3
节点版本:v16.14.0
Vue-版本:@vue/cli 5.0.1

路径中包含以下文件夹:

├── README.md
├── babel.config.js
├── dist
├── jsconfig.json
├── node_modules
├── package-lock.json
├── package.json
├── public
├── src
└── vue.config.js

您知道为什么这不起作用吗?不幸的是,我通过网络搜索没有找到解决方案

if I create a new vue.js project on my macbook and compile it with "npm run serve", I get the following error.
I haven't changed any file since creating it.

markus@Markuss-MBP meinerstesprojekt % npm run serve

> [email protected] serve
> vue-cli-service serve

 INFO  Starting development server...


 ERROR  Failed to compile with 1 error                                                                                                                                    6:12:51 PM

 error  

Conflict: Multiple assets emit different content to the same filename index.html

ERROR in Conflict: Multiple assets emit different content to the same filename index.html

webpack compiled with 1 error

vue.config.js

const { defineConfig } = require('@vue/cli-service')
module.exports = defineConfig({
transpileDependencies: true
})

module.exports = {
chainWebpack: (config) => {
config.resolve.symlinks(true)
}
}

package.json

{
  "name": "meinerstesprojekt",
  "version": "0.1.0",
  "private": true,
  "scripts": {
    "serve": "vue-cli-service serve",
    "build": "vue-cli-service build",
    "lint": "vue-cli-service lint"
  },
  "dependencies": {
    "core-js": "^3.8.3",
    "vue": "^2.6.14"
  },
  "devDependencies": {
    "@babel/core": "^7.12.16",
    "@babel/eslint-parser": "^7.12.16",
    "@vue/cli-plugin-babel": "~5.0.0",
    "@vue/cli-plugin-eslint": "~5.0.0",
    "@vue/cli-service": "^5.0.1",
    "eslint": "^7.32.0",
    "eslint-plugin-vue": "^8.0.3",
    "vue-template-compiler": "^2.6.14"
  },
  "eslintConfig": {
    "root": true,
    "env": {
      "node": true
    },
    "extends": [
      "plugin:vue/essential",
      "eslint:recommended"
    ],
    "parserOptions": {
      "parser": "@babel/eslint-parser"
    },
    "rules": {}
  },
  "browserslist": [
    "> 1%",
    "last 2 versions",
    "not dead"
  ]
}

npm version: 8.5.3
Node-Version: v16.14.0
Vue-Version: @vue/cli 5.0.1

The following folders are in the path:

├── README.md
├── babel.config.js
├── dist
├── jsconfig.json
├── node_modules
├── package-lock.json
├── package.json
├── public
├── src
└── vue.config.js

Do you know why this doesn't work? Unfortunately, I couldn't find the solution by searching the web

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

盗心人 2025-01-19 20:37:17

我遇到这个问题是因为项目的路径在文件夹名称中包含空格,

所以我重命名了项目的路径并且它可以工作

示例
来自用户/此处的某个路径/您的项目名称
user/somePathHere/your-project-name

一切开始工作。

i was having this issue because of the path to the project was having spaces in the folders name

so i renamed the paths to the project and it works

Example
from user/some path here/your-project-name
to user/somePathHere/your-project-name

and everything starts to work.

雨后彩虹 2025-01-19 20:37:17

解决方案:

第一步:将index.html重命名为index.ejs;

步骤2:在node_nodules/webpack/bin/webpack.js中添加html: { template: './src/index.ejs' }

错误原因可能是:使用脚手架创建项目时,多个文件被重复。

Solution:

Step 1: Rename index.html to index.ejs;

Step 2: Add html: { template: './src/index.ejs' } to node_nodules/webpack/bin/webpack.js

The reason for the error may be: When the scaffolding was used to create a project, the names of multiple files were duplicated.

冰火雁神 2025-01-19 20:37:17

由于路径中的“(”和“)”,我遇到了问题。
只需从路径中删除括号即可。

I met the issue problem because of "(" and ")" in the path.
Just remove parentheses from path.

三生路 2025-01-19 20:37:17

这个解决方案对我有用:我的项目的文件夹路径有“(”和“)”,我删除了它们,并且 npm runserve 工作正常。路径也有空格“ ”,但这并不重要。

This solution worked for me: The folder path to my project had '(' and ')' I removed them and npm run serve works fine. Also the path have spaces ' ' but it doesn't matter.

寂寞陪衬 2025-01-19 20:37:17

根文件夹中的 webpack.config.js 文件如下所示,我必须注释掉 HtmlWebpackPlugin 声明:

'use strict'
const { VueLoaderPlugin } = require('vue-loader')
const HtmlWebpackPlugin = require('html-webpack-plugin')

module.exports = {
  mode: 'development',
  entry: [
    './src/app.js'
  ],
  module: {
    rules: [
      {
        test: /\.vue$/,
        use: 'vue-loader'
      }
    ]
  },
  plugins: [
    new VueLoaderPlugin(),
    // new HtmlWebpackPlugin({
    //   filename: 'index.html',
    //   template: 'index.html',
    //   inject: true
    // })
  ]
}

然后它就起作用了。

My webpack.config.js file in the root folder looked like this and I had to comment out the HtmlWebpackPlugin declarations:

'use strict'
const { VueLoaderPlugin } = require('vue-loader')
const HtmlWebpackPlugin = require('html-webpack-plugin')

module.exports = {
  mode: 'development',
  entry: [
    './src/app.js'
  ],
  module: {
    rules: [
      {
        test: /\.vue$/,
        use: 'vue-loader'
      }
    ]
  },
  plugins: [
    new VueLoaderPlugin(),
    // new HtmlWebpackPlugin({
    //   filename: 'index.html',
    //   template: 'index.html',
    //   inject: true
    // })
  ]
}

Then it worked.

浪漫之都 2025-01-19 20:37:17

当您点击 vue create your-project-name 选择 ([Vue 3] babel,eslint)
并尝试npm runserve

您还可以使用 vue ui 启动一个新项目或导入旧项目,并在浏览器的 GUI 中查看项目运行的所有内容,以便找出任何问题。

When you hit vue create your-project-name Select ([Vue 3] babel,eslint)
and try to npm run serve.

And also you can use vue ui to start a new project or import old one, and see everything about your project run in a GUI in your browser so you can figure out any problem.

So要识趣 2025-01-19 20:37:17

如果将 public/index.html 替换为 public/index2.html 并运行它,它将运行良好。

If you replace public/index.html with public/index2.html and run it, it will run well.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文