Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create bundle with Webpack using third party UMD libraries #36

Open
luenmuvel opened this issue May 3, 2020 · 3 comments
Open

Create bundle with Webpack using third party UMD libraries #36

luenmuvel opened this issue May 3, 2020 · 3 comments

Comments

@luenmuvel
Copy link

I am trying to make a library that makes use your cybersource-rest-client library. When I worked with this library in Nodejs I had no problems but I need to use it in the client side (Browser) too, but I get the following error when compiling with Webpack:

ERROR in ./node_modules/cybersource-rest-client/src/index.js
Module not found: Error: Can't resolve 'model/TmsV1InstrumentIdentifiersPaymentInstrumentsGet200ResponseEmbeddedBuyerInformation' in 'C:\Users\MSI\Belcorp\sdk\node_modules\cybersource-rest-client\src'
 @ ./node_modules/cybersource-rest-client/src/index.js 19:4-35645
 @ ./src/providers/cybersource/process-payment.js
 @ ./src/providers/Provider.js
 @ ./src/index.js

ERROR in ./node_modules/cybersource-rest-client/src/index.js
Module not found: Error: Can't resolve 'model/TmsV1InstrumentIdentifiersPaymentInstrumentsGet200ResponseEmbeddedBuyerInformationIssuedBy' in 'C:\Users\MSI\Belcorp\sdk\node_modules\cybersource-rest-client\src'
 @ ./node_modules/cybersource-rest-client/src/index.js 19:4-35645
 @ ./src/providers/cybersource/process-payment.js
 @ ./src/providers/Provider.js
 @ ./src/index.js

ERROR in ./node_modules/cybersource-rest-client/src/index.js
Module not found: Error: Can't resolve 'model/TmsV1InstrumentIdentifiersPaymentInstrumentsGet200ResponseEmbeddedBuyerInformationPersonalIdentification' in 'C:\Users\MSI\Belcorp\sdk\node_modules\cybersource-rest-client\src' @ ./node_modules/cybersource-rest-client/src/index.js 19:4-35645
 @ ./src/providers/cybersource/process-payment.js
 @ ./src/providers/Provider.js
 @ ./src/index.js

ERROR in ./node_modules/cybersource-rest-client/src/index.js
Module not found: Error: Can't resolve 'model/TmsV1InstrumentIdentifiersPaymentInstrumentsGet200ResponseEmbeddedCard' in 'C:\Users\MSI\Belcorp\sdk\node_modules\cybersource-rest-client\src'
 @ ./node_modules/cybersource-rest-client/src/index.js 19:4-35645
 @ ./src/providers/cybersource/process-payment.js
 @ ./src/providers/Provider.js
 @ ./src/index.js

ERROR in ./node_modules/cybersource-rest-client/src/index.js
Module not found: Error: Can't resolve 'model/TmsV1InstrumentIdentifiersPaymentInstrumentsGet200ResponseEmbeddedEmbedded' in 'C:\Users\MSI\Belcorp\sdk\node_modules\cybersource-rest-client\src'
 @ ./node_modules/cybersource-rest-client/src/index.js 19:4-35645
 @ ./src/providers/cybersource/process-payment.js
 @ ./src/providers/Provider.js
 @ ./src/index.js

ERROR in ./node_modules/cybersource-rest-client/src/index.js
Module not found: Error: Can't resolve 'model/TmsV1InstrumentIdentifiersPaymentInstrumentsGet200ResponseEmbeddedEmbeddedInstrumentIdentifier' in 'C:\Users\MSI\Belcorp\sdk\node_modules\cybersource-rest-client\src'
 @ ./node_modules/cybersource-rest-client/src/index.js 19:4-35645
 @ ./src/providers/cybersource/process-payment.js
 @ ./src/providers/Provider.js
 @ ./src/index.js

ERROR in ./node_modules/cybersource-rest-client/src/index.js
Module not found: Error: Can't resolve 'model/TmsV1InstrumentIdentifiersPaymentInstrumentsGet200ResponseEmbeddedLinks' in 'C:\Users\MSI\Belcorp\sdk\node_modules\cybersource-rest-client\src'
 @ ./node_modules/cybersource-rest-client/src/index.js 19:4-35645
 @ ./src/providers/cybersource/process-payment.js
 @ ./src/providers/Provider.js
 @ ./src/index.js

// and many more similar mistakes

When I inspect the library in the node_modules/ directory I find that said file has the following structure:

(function(factory) {
  if (typeof define === 'function' && define.amd) {
    // AMD. Register as an anonymous module.
    define(['ApiClient', 'model/AddNegativeListRequest', 'model/AuthReversalRequest', 'model/AuthorizationOptions', 'model/BillTo', 'model/BuyerInformation', 'model/CapturePaymentRequest', 'model/CardInfo', 'model/CheckPayerAuthEnrollmentRequest', 'model/CreateAdhocReportRequest', 'model/CreateCreditRequest', 'model/CreateDecisionManagerCaseRequest', 'model/CreateInstrumentIdentifierRequest', 'model/CreateInvoiceRequest', 'model/CreatePaymentInstrumentRequest', 'model/CreatePaymentRequest', 'model/CreateReportSubscriptionRequest', 'model/CreateSearchRequest', 'model/DerPublicKey', 'model/Detail', 'model/EmbeddedInstrumentIdentifierRequest', 'model/EmbeddedInstrumentIdentifierResponse', 'model/Error', 'model/ErrorBean', 'model/ErrorFieldBean', 'model/ErrorLinks', 'model/ErrorResponse', 'model/ErrorResponseWithHAL', 
// and many more similar statements
  }
}

In my webpack.config.js file settings I have the following:

const path = require('path');
const HtmlWebPackPlugin = require('html-webpack-plugin');


module.exports = {
  mode: 'development',
  entry: './src/index.js',
  output: {
    path: path.resolve(__dirname, 'dist'),
    filename: 'my-payment-library.js',
    libraryTarget: 'umd'
  },
  module: {
    rules: [
      {
        test: /\.m?js$/,
        exclude: /(node_modules)/,
        use: {
          loader: 'babel-loader',
          options: {
            presets: ['@babel/preset-env']
          }
        }
      }
    ],
  },
  node: {
    fs: 'empty'
  }
};

I would appreciate any help.

@gnongsie
Copy link
Contributor

gnongsie commented May 5, 2020

Hi @luenmuvel,

Can you try removing this line from the webpack.config.js?

exclude: /(node_modules)/,

Let me know if this helps. If not, I will be happy to provide further assistance.

@Morriphi
Copy link

Morriphi commented Jun 6, 2022

Any update on this issue? I'm currently having issues trying to bundle.

@aliliarif
Copy link

Any update on this issue? I am also having trouble when trying to bundle using webpack - getting same errors as described by @luenmuvel

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants