1

I wrote a component in reactJS that renders a tree

component sample I am unable to import it directly to browser and keep getting this error:

Uncaught Error: Module name "TreeComponent" has not been loaded yet for context: _. Use require([])
http://requirejs.org/docs/errors.html#notloaded
    at makeError (require.js:5)
    at Object.o [as require] (require.js:5)
    at requirejs (require.js:5)
    at reactJS_returnReactJs.action:2192

babel preset is react-app:

  "babel": {
    "presets": [
      "react-app"
    ]
  },

entry point for build is index.js:

enter image description here

export {default} from './components/TreeComponent';

Can you help me to find out what is wrong in my build steps?

Danilo Silva
  • 121
  • 10

1 Answers1

0

If you export react component in your TreeComponent.js this way

export default TreeComponent({

});

Or something like this

exports.default = TreeComponent;

You need to import it this way

import { TreeComponent } from './components/TreeComponent';

Or you can do this way too

import TreeComponent from './components/TreeComponent/TreeComponent';
Hana Alaydrus
  • 2,225
  • 16
  • 19
  • Last statement from TreeComponent is the export export default TreeComponent; I then add the main.js file created to the browser, but I cannot reference it in inline scripts at all. – Danilo Silva Jul 26 '17 at 11:17