launchdarkly / vue-client-sdk

LaunchDarkly Client-side SDK for Vue
Other
4 stars 7 forks source link

Vue CLI/Webpack builds fail due to apparently incorrect order of export properties in package.json #29

Closed hughblackall closed 1 year ago

hughblackall commented 1 year ago

Describe the bug I was recently trying to introduce this library to a Vue 3 application that is based on the Vue CLI/Webpack and ran into an error at build time:

Module not found: Error: Default condition should be last one

Whilst the error doesn't mention the launchdarkly-vue-client-sdk package specifically, removing the import of this package also removes the error.

To reproduce

  1. Scaffold a new Vue CLI project using e.g.
    yarn global add @vue/cli
    vue create test-project
  2. Install this library
    yarn add launchdarkly-vue-client-sdk
  3. Import the library in e.g. main.js

    import { createApp } from 'vue'
    import { LDPlugin } from "launchdarkly-vue-client-sdk";
    import App from './App.vue'
    
    createApp(App).use(LDPlugin).mount('#app')
  4. Run or build the app
    yarn serve

Expected behavior The library is able to be imported without throwing errors in Webpack builds

Logs During a Webpack build:

 ERROR  Failed to compile with 1 error

 error  in ./src/main.js

Module not found: Error: Default condition should be last one

ERROR in ./src/main.js 2:0-55
Module not found: Error: Default condition should be last one

webpack compiled with 1 error

SDK version 2.0.2

Language version, developer tools Node v18.17.0, Webpack 5.88.2, @vue/cli-service 5.0.8

OS/platform macOS 13.4.1

Additional context The cause seems to be the exports property in the package.json. I was able to patch the library on my machine by swapping the order of the default and types properties in each section of exports like so:

"exports": {
    "import": {
      "types": "./dist/src/index.d.ts",
      "default": "./dist/launchdarkly-vue-client-sdk.es.js"
    },
    "require": {
      "types": "./dist/src/index.d.ts",
      "default": "./dist/launchdarkly-vue-client-sdk.umd.js"
    }
  }

and this resolved the issue.

It looks like the Firebase JS SDK had a similar issue earlier this year:

https://github.com/firebase/firebase-js-sdk/issues/7005

yusinto commented 1 year ago

Thank you for reporting this. We are investigating and will provide an update soon. Internally logged as 212039.

yusinto commented 1 year ago

This has been fixed in release 2.0.3.