javascript 无法读取未定义的属性“main”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23806236/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Cannot read property 'main' of undefined
提问by Joshua Barnett
So my project structures is I have a src
and www
directory in my root ./
, which also contains my bower.json
, gulpfile.js
, and .bowerrc
with the directory
set to ./www/bower/
.
所以我的项目结构是我有一个src
和www
目录在我的根./
,其中还包含我的bower.json
,gulpfile.js
和.bowerrc
与directory
设置为./www/bower/
。
I have an index.html
in my ./src
and I've setup a gulp task that pipes it through wiredep
and out to the ./www
where the bower packages are.
我有一个index.html
,我./src
已经设置了一个 gulp 任务,将它通过管道输送wiredep
到./www
凉亭包所在的位置。
Unfortunately it adds all the dependecies as if it's in the ./src
directory so all of them are prefixed like ../www/bower/
which does work as the final index.html
ends up in the www
directory so I fiddled with some of the wiredep
configuration options like so:
不幸的是,它添加了所有依赖项,就好像它在./src
目录中一样,因此所有依赖项都带有前缀,就像../www/bower/
最终index.html
在www
目录中一样起作用,所以我摆弄了一些wiredep
配置选项,如下所示:
gulp.task('bower', function () {
gulp.src('./src/index.html')
.pipe(wiredep({
cwd: './www',
bowerJson: require('./bower.json'),
directory: '../.bowerrc'
}))
.pipe(gulp.dest('./www'));
});
However I get the following error:
但是我收到以下错误:
stream.js:94
throw er; // Unhandled stream error in pipe.
^
TypeError: Cannot read property 'main' of undefined
at findMainFiles (D:\Dropbox\University\MindFlipDOM\node_modules\wiredep\lib\detect-dependencies.js:53:37)
at D:\Dropbox\University\MindFlipDOM\node_modules\wiredep\lib\detect-dependencies.js:111:17
at forOwn (D:\Dropbox\University\MindFlipDOM\node_modules\wiredep\node_modules\lodash\dist\lodash.js:1301:15)
at Function.forEach (D:\Dropbox\University\MindFlipDOM\node_modules\wiredep\node_modules\lodash\dist\lodash.js:2595:9)
at detect (D:\Dropbox\University\MindFlipDOM\node_modules\wiredep\lib\detect-dependencies.js:312:5)
at wiredep (D:\Dropbox\University\MindFlipDOM\node_modules\wiredep\wiredep.js:178:39)
at Transform._transform (D:\Dropbox\University\MindFlipDOM\node_modules\wiredep\wiredep.js:217:34)
at Transform._read (D:\Dropbox\University\MindFlipDOM\node_modules\wiredep\node_modules\through2\node_modules\readable-stream\lib\_stream_transform.js:184:10)
at Transform._write (D:\Dropbox\University\MindFlipDOM\node_modules\wiredep\node_modules\through2\node_modules\readable-stream\lib\_stream_transform.js:172:12)
at doWrite (D:\Dropbox\University\MindFlipDOM\node_modules\wiredep\node_modules\through2\node_modules\readable-stream\lib\_stream_writable.js:238:10)
So what am I doing wrong?
那我做错了什么?
回答by Chandramuralis
Also try, this will make sure to download the necessary modules that were missing.
也尝试一下,这将确保下载丢失的必要模块。
bower install
回答by Bipin Bhandari
Well as far as I can guess, you messed up with bower. Most likely you uninstalled a dependency and forgot to save.
好吧,据我所知,你把 bower 搞砸了。很可能您卸载了依赖项而忘记保存。
What you should have done:
你应该做的:
bower uninstall <dependency> --save
What you probably did:
你可能做了什么:
bower uninstall <dependency>
You can solve this issue by bower executing uninstall <dependency> --save
or if you are unsure of which components you uninstalled, you can edit bower.json
file and remove components that are not installed. (You can check if a dependency is installed in bower_componenets
directory)
您可以通过执行 bower 来解决此问题,uninstall <dependency> --save
或者如果您不确定卸载了哪些组件,您可以编辑bower.json
文件并删除未安装的组件。(您可以检查bower_componenets
目录中是否安装了依赖项)