admin管理员组文章数量:1332345
I am trying to move all react ponents to separate repo so that they can be shared. I am getting the above error
ui-react/index.js
'use strict';
import Button from "./ponents/Button/Button";
module.exports.Button = Button;
FileB
import {Button} from 'ui-react';
When i do this i get an error called.
'ui-react' does not contain an export named 'Button'
PS: In package.json of ui-react i have set main to index.js and i have also tried import "ui-react/index"
I am trying to move all react ponents to separate repo so that they can be shared. I am getting the above error
ui-react/index.js
'use strict';
import Button from "./ponents/Button/Button";
module.exports.Button = Button;
FileB
import {Button} from 'ui-react';
When i do this i get an error called.
'ui-react' does not contain an export named 'Button'
PS: In package.json of ui-react i have set main to index.js and i have also tried import "ui-react/index"
Share Improve this question asked Nov 15, 2017 at 17:21 aWebDeveloperaWebDeveloper 38.4k41 gold badges177 silver badges247 bronze badges 5-
2
Why are you using
module.exports
instead ofexport { Button };
? Usually mixing module formats is bad idea. – loganfsmyth Commented Nov 15, 2017 at 17:23 - 1 lack of knowlege – aWebDeveloper Commented Nov 15, 2017 at 17:26
- Fair enough! :) – loganfsmyth Commented Nov 15, 2017 at 17:32
- can you share more links on this or enlighten me – aWebDeveloper Commented Nov 15, 2017 at 17:34
-
1
You could read through 2ality./2014/09/es6-modules-final.html or any number of other posts about ES6 module syntax.
require
andmodule.exports
are part of the alternativeCommonJS
module format. The main thing is that you shouldn't really use both together. Some build tooling does allow it, but it usually leads to confusion like this. – loganfsmyth Commented Nov 15, 2017 at 18:22
1 Answer
Reset to default 7No need to write module.exports. You can write
export { Button };
本文标签: javascriptmoduleexports Cannot set property of undefinedStack Overflow
版权声明:本文标题:javascript - module.exports Cannot set property of undefined - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742326300a2453795.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论