launchdarkly / js-client-sdk

LaunchDarkly Client-side SDK for Browser JavaScript
Other
109 stars 62 forks source link

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

Open rrawat-dev opened 1 week ago

rrawat-dev commented 1 week 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 1 week 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 1 week ago

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

rrawat-dev commented 1 week ago

Hi Ryan,

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

kinyoklion commented 6 days 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 6 days 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 6 days ago

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