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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-28 01:35:56  来源:igfitidea点击:

Cannot read property 'main' of undefined

javascriptnode.jsbowergulp

提问by Joshua Barnett

So my project structures is I have a srcand wwwdirectory in my root ./, which also contains my bower.json, gulpfile.js, and .bowerrcwith the directoryset to ./www/bower/.

所以我的项目结构是我有一个srcwww目录在我的根./,其中还包含我的bower.jsongulpfile.js.bowerrcdirectory设置为./www/bower/

I have an index.htmlin my ./srcand I've setup a gulp task that pipes it through wiredepand out to the ./wwwwhere the bower packages are.

我有一个index.html,我./src已经设置了一个 gulp 任务,将它通过管道输送wiredep./www凉亭包所在的位置。

Unfortunately it adds all the dependecies as if it's in the ./srcdirectory so all of them are prefixed like ../www/bower/which does work as the final index.htmlends up in the wwwdirectory so I fiddled with some of the wiredepconfiguration options like so:

不幸的是,它添加了所有依赖项,就好像它在./src目录中一样,因此所有依赖项都带有前缀,就像../www/bower/最终index.htmlwww目录中一样起作用,所以我摆弄了一些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> --saveor if you are unsure of which components you uninstalled, you can edit bower.jsonfile and remove components that are not installed. (You can check if a dependency is installed in bower_componenetsdirectory)

您可以通过执行 bower 来解决此问题,uninstall <dependency> --save或者如果您不确定卸载了哪些组件,您可以编辑bower.json文件并删除未安装的组件。(您可以检查bower_componenets目录中是否安装了依赖项)