Vue-cli 运行构建 TypeError 'name' 未定义 [英] Vue-cli run build TypeError 'name' Undefined
问题描述
我刚开始使用 vue-cli 时遇到了问题.
I just started to use vue-cli and I got stock with a problem.
按照文档说明:
- 我安装了 vue/cli
npm install -g @vue/cli
(版本 3.11.0). 我创建了一个项目
vue create test
(默认配置)和cd
到文件夹中.
- I installed vue/cli
npm install -g @vue/cli
(version 3.11.0). I created a project
vue create test
(default config) andcd
into the folder.
但是当我尝试构建项目 npm run build
时,我遇到了这个错误.
But when I tried to build the project npm run build
, I got this error.
TypeError: Cannot read property 'name' of undefined
at entrypoint.getFiles.reduce (C:\Users\MyUser\test\node_modules\webpack\lib\performance\SizeLimitsPlugin.js:43:25)
at Array.reduce (<anonymous>)
at getEntrypointSize (C:\Users\MyUser\test\node_modules\webpack\lib\performance\SizeLimitsPlugin.js:40:27)
at compiler.hooks.afterEmit.tap.compilation (C:\Users\MyUser\test\node_modules\webpack\lib\performance\SizeLimitsPlugin.js:75:18)
at _next0 (eval at create (C:\Users\MyUser\test\node_modules\tapable\lib\HookCodeFactory.js:33:10), <anonymous>:10:1)
at _err0 (eval at create (C:\Users\MyUser\test\node_modules\tapable\lib\HookCodeFactory.js:33:10), <anonymous>:24:1)
at callback (C:\Users\MyUser\test\node_modules\copy-webpack-plugin\dist\index.js:126:17)
at afterEmit (C:\Users\MyUser\test\node_modules\copy-webpack-plugin\dist\index.js:220:13)
at AsyncSeriesHook.eval [as callAsync] (eval at create (C:\Users\MyUser\test\node_modules\tapable\lib\HookCodeFactory.js:33:10), <anonymous>:20:1)
at AsyncSeriesHook.lazyCompileHook (C:\Users\MyUser\test\node_modules\tapable\lib\Hook.js:154:20)
at asyncLib.forEachLimit.err (C:\Users\MyUser\test\node_modules\webpack\lib\Compiler.js:482:27)
at C:\Users\MyUser\test\node_modules\neo-async\async.js:2818:7
at done (C:\Users\MyUser\test\node_modules\neo-async\async.js:3522:9)
at AsyncSeriesHook.eval [as callAsync] (eval at create (C:\Users\MyUser\test\node_modules\tapable\lib\HookCodeFactory.js:33:10), <anonymous>:6:1)
at outputFileSystem.writeFile.err (C:\Users\MyUser\test\node_modules\webpack\lib\Compiler.js:464:33)
at C:\Users\MyUser\test\node_modules\graceful-fs\graceful-fs.js:57:14
我在我电脑的不同文件夹中尝试过,以防某些文件有冲突但没有运气.知道我该如何解决这个问题吗?
I tried it in different folders of my PC in case some file were having conflict but with no luck. Any idea how can I solve this?
推荐答案
更新: 这是 Webpack 4.40.0 和 4.40.1 中的一个错误,现在应该是 已修复.
Update: This was a bug in Webpack 4.40.0 and 4.40.1 and should now be fixed.
Webpack 的 SizeLimitsPlugin.js
的第 43 行可以在这里看到:
Line 43 of Webpack's SizeLimitsPlugin.js
can be seen here:
正如错误消息所暗示的那样,它正在尝试访问 asset.name
.
As suggested by the error message it is trying to access asset.name
.
这行似乎在最近几天发生了变化,并且在 4.40.0 版本中进行了更改.我对该代码不够熟悉,无法确定是否应归咎于错误,但它是可疑的.
It would appear that this line got changed in the last few days and the change made it into the 4.40.0 release. I don't have enough familiarity with that code to say for sure whether it is to blame for the error but it is suspicious.
其他 Vue 用户似乎也遇到了同样的问题:
It seems that other Vue users have run into the same problem:
https://github.com/vuejs/vue-cli/issues/4572
那里建议了几种解决方法.例如:
Several workarounds are suggested there. e.g.:
在您的 package.json
旁边创建一个名为 vue.config.js
的文件,并将以下代码添加到该文件中:
Create a file called vue.config.js
alongside your package.json
and add the following code to that file:
module.exports = {
css: {
sourceMap: true
}
}
或者您可以使用:
module.exports = {
productionSourceMap: false
}
或:
module.exports = {
configureWebpack: {
devtool: "eval-source-map"
}
}
有关这些功能的更多信息,请参见 https://cli.vuejs.org/config/#vue-config-js
For more information on what these do see https://cli.vuejs.org/config/#vue-config-js
设置 sourceMap: true
和 productionSourceMap: false
也可以通过 UI 设置,如果你运行 vue ui
并进入配置为您的项目.
The settings sourceMap: true
and productionSourceMap: false
can also be set via the UI if you run vue ui
and go into the configuration for your project.
这篇关于Vue-cli 运行构建 TypeError 'name' 未定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!