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 of export { 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 and module.exports are part of the alternative CommonJS 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
Add a ment  | 

1 Answer 1

Reset to default 7

No need to write module.exports. You can write

export { Button };

本文标签: javascriptmoduleexports Cannot set property of undefinedStack Overflow