I'm using React and ES6 using babel and webpack. I am very new to this ecosystem.
I am trying to import some common utility functions into my jsx file but react is unable to find the file
homepage.jsx
var pathToRoot = './../..'; import path from 'path'; import React from 'react'; import ReactDOM from 'react-dom'; var nextWrappedIndex = require(path.join(pathToRoot,'/lib/utils.js')).nextWrappedIndex; //some react/JSX code utils.js
var nextWrappedIndex = function(dataArray) { //some plain js code return newIndex; } exports.nextWrappedIndex = nextWrappedIndex; Directory structure is as follows:
src |--app.js |--components | |--homepage | |--homepage.jsx | |--lib | |--utils.js I am on a windows 10 machine and was facing issues during compilation providing the path by any other means. Using path.join solved compilation issue but the browser while rendering throws this error Uncaught Error: Cannot find module '../../lib/utils.js'.
How do I accomplish this?
Also, is this the best way to do it(if altogether it is way it is supposed to be done in such ecosystem)?