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

问题描述 投票:0回答:4

如果我在我的 macbook 上创建一个新的 vue.js 项目并使用“npm run serve”编译它,我会收到以下错误。
自创建文件以来我没有更改任何文件。
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

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

node.js vue.js npm assets conflict
4个回答
6
投票

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

所以我重命名了项目的路径并且它有效

例子
来自

user/some path here/your-project-name

user/somePathHere/your-project-name

一切开始工作。


3
投票

解决方案:

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

第二步:添加 html: { template: './src/index.ejs' } 到 node_nodules/webpack/bin/webpack.js

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


0
投票

我的根文件夹中的

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
    // })
  ]
}

然后就成功了。


-1
投票

当你点击

vue create your-project-name
选择([Vue 3] babel,eslint) 并尝试
npm run serve
.

您还可以使用

vue ui
启动新项目或导入旧项目,并在浏览器的 GUI 中查看项目的所有运行情况,这样您就可以找出任何问题。

© www.soinside.com 2019 - 2024. All rights reserved.