launchdarkly / js-client-sdk

LaunchDarkly Client-side SDK for Browser JavaScript
Other
113 stars 66 forks source link

Unable to load launchdarkly-js-client-sdk/ldclient.es.js using webpack 2 #301

Closed rrawat-dev closed 4 months ago

rrawat-dev commented 5 months ago

I am getting following error while trying to load launchdarkly-js-client-sdk using webpack 2:

ERROR in ./~/launchdarkly-js-client-sdk/dist/ldclient.es.js Module parse failed: node_modules/launchdarkly-js-client-sdk/dist/ldclient.es.js Unexpected token (1:3500)

You may need an appropriate loader to handle this file type.

File content to load from node_module/launchdarkly-js-client-sdk/dist/ldclient.es.js https://unpkg.com/launchdarkly-js-client-sdk@3.4.0/dist/ldclient.min.js

webpack loader config: { test: /\.es\.js$/, use: [{ loader: 'babel-loader', options: [{ presets: [['babel-preset-env']] }] }] } error after above config:

ERROR in ./~/launchdarkly-js-client-sdk/dist/ldclient.es.js Module build failed: Syntax Error: node_modules/launchdarkly-js-client-sdk/dist/ldclient.es.js Unexpected token, expected ( (1:37325)

kinyoklion commented 5 months ago

Hello @rrawat-dev,

Is this a new issue you are encountering with a SDK version update, or is this a new implementation?

Thank you, Ryan

kinyoklion commented 5 months ago

Also, to clarify, what specific version of webpack are you using?

rrawat-dev commented 5 months ago

Hi Ryan,

Integrating LaunchDarkly first time with an existing project setup (Webpack ^2.2.1).

kinyoklion commented 5 months ago

Thank you @rrawat-dev. I will see if I can get it working with that version, but it is likely there will be problems as that webpack version was released 7 years ago and therefore doesn't handle many language features.

kinyoklion commented 5 months ago

@rrawat-dev What version of babel-loader are you using? The error here seems to be that webpack 2 doesn't support arrow functions, at least not as class properties. (There are many arrow functions used in the SDK, but the first encountered is where the error message is.)

You will likely need a babel plugin which transforms arrow function class properties. Most of the babel packages that old are archived, which makes locating the correct one difficult.

kinyoklion commented 5 months ago

Theoretically something like babel-plugin-transform-class-properties.

rrawat-dev commented 5 months ago

Hi @kinyoklion, Upgraded to webpack 5. Working fine now.

kinyoklion commented 4 months ago

@rrawat-dev Great, thank you for letting me know! I am going to close this issue.