Giter Site home page Giter Site logo

Comments (11)

pospi avatar pospi commented on July 19, 2024

It should also be mentioned that the above fixes won't actually resolve issues when including the module as-is, only when including the cjsx source. You'll have to configure webpack to define a browser-check environment variable and support coffeescript/react transforms; then you should be able to use something similar to the below to work around the issue:

var ReactCardFormContainer;
if (process.env.IS_BROWSER) {
  ReactCardFormContainer = require('card-react/src/components/card-react-form-container.cjsx');
} else {
  ReactCardFormContainer = require('card-react');
}

from card-react.

vitalybe avatar vitalybe commented on July 19, 2024

What is that for?

} else {
  ReactCardFormContainer = require('card-react');
}

Why not to require cjsx always directly?

from card-react.

pospi avatar pospi commented on July 19, 2024

It's to do with the way webpack checks files when building. My understanding is basically-

  • if you're running in a node environment, you generally want to load precompiled ES5 files to avoid parsing them at runtime. This should be the default behaviour of a module - you don't want to force anyone integrating your library to have to prehandle your module with coffeeify.
  • if you're running in webpack, then weback wants to handle your build process for you. This means it wants you to reference source files from your own source files; in fact if you don't it will throw a critical error that you're using preminified files and abort. Hence the two different require paths.

from card-react.

shatran avatar shatran commented on July 19, 2024

@pospi i'm kinda new to webpack, so i'll ask you this:
If I'll change card-react.js file in the root folder from

module.exports = require('./lib/card-react-form-container');

to

var ReactCardFormContainer;
if (process.env.IS_BROWSER) {
  ReactCardFormContainer = require('src/components/card-react-form-container.cjsx');
} else {
  ReactCardFormContainer = require('lib/card-react-form-container');
}
module.exports = ReactCardFormContainer;

and will change the main file in package.json to card-react.js

will it allow webpack to include the module as-is? and in the same time not interfering with the non-webpack require?

from card-react.

pospi avatar pospi commented on July 19, 2024

Hey there, after looking into it unfortunately things are a bit more complicated than that. Definitely leave your main export as-is.

I should have mentioned in my earlier post, but IS_BROWSER is a check specific to the app I'm currently working on. Webpack provides a plugin for setting variables in your compilation process, so the way I determine whether I'm running things serverside in node vs. clientside via a compiled webpack build is to use DefinePlugin to set an environment variable I can switch on.

It's a workaround to be sure, but it's enough to get webpack running. The real issue is that @jessepollak has precompiled payment's modules (payment itself and qj) all into the same file, and I believe it's multiple instances of module.exports within one source file that webpack specifically complains about (it's not technically valid node module structure either, but it'll work).

The real fix would be for all modules to compile their files into separate source files and to reference each other separately, so the final build of payment should only include its own source in payment/payment.js and still reference QJ by requireing directly from node_modules. If that change was completed then card-react would be able to load payment by its main entrypoint under both node and webpack without issues.

I'll leave it up to you guys as to whether you think it's worth fixing, with things as they are at the moment it's possible to get both your modules working under either environment so I'm happy either way (:

from card-react.

shatran avatar shatran commented on July 19, 2024

@pospi I've released version 1.0.18 a few days ago with the merged fix and with the new payment version. I'll be happy to know if it worked for you. Thanks!

from card-react.

nicoecheza avatar nicoecheza commented on July 19, 2024

Hi @shatran
We are using this module, but we are still having the "Not found module payment/src/payment" which seems pretty reasonable since we are using v3 of npm and the "payment" dependency it's being installed independently from card-react. For now, we bypassed the error editing the "card-react-form-container.js" and "card-react-component.js" files to just require "payment" as an independent module (Payment = require('payment')).
But it would be nice to have a solution for this.

Yes, we are using webpack too 💃

from card-react.

shatran avatar shatran commented on July 19, 2024

HI @nicoecheza,
Thanks for your comment. are you using version 1.0.18 of card-react? i added payment there as a dependency.

from card-react.

nicoecheza avatar nicoecheza commented on July 19, 2024

Yes, we are.

from card-react.

shatran avatar shatran commented on July 19, 2024

I've decided to restore the old require (Payment = require('payment'). I think that's the right way, and like @pospi said "The real fix would be for all modules to compile their files into separate source files and to reference each other separately". so by doing this + hoping the payment requiring qj issue will be solved, it should work fine. @nicoecheza please use version 1.0.19 and let me know if it solved your issue.

from card-react.

nicoecheza avatar nicoecheza commented on July 19, 2024

@shatran nice, thanks you!

from card-react.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.