I have a react app that is created using https://github.com/facebook/create-react-app
but I'd like to import some code that is shared with a NodeJs project (and thus use the commonjs
syntax)
The code is exported with
exports.Agreement = agreement
When I import that code in my project using
const Agreement = require('../../common/model/agreement').Agreement
I start getting this error in my browser:
ReferenceError: exports is not defined
Module.../common/model/agreement.js
/Users/teone/Sites/cla-manager/common/model/agreement.js:217
214 |
215 | export const AgreementType = agreementType;
216 | export const AgreementCollection = agreementCollection;
> 217 | exports.Agreement = agreement;
Is commonJs
supported in CRA? Is it possible to achieve this without ejecting
the project?
Couldn't find any solution to it out on the web, just abandoned discussions.
A solution would be to migrate the NodeJs code to es7
import/export
but then I'll have to transpile that, and I would like to avoid this unnecessary step.
Any advice is much appreciated