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

dependency was not found (browser) #1137

Open
luandro opened this issue Oct 8, 2021 · 1 comment
Open

dependency was not found (browser) #1137

luandro opened this issue Oct 8, 2021 · 1 comment

Comments

@luandro
Copy link

luandro commented Oct 8, 2021

Expected Behavior

Should load balena-sdk on the browser using NuxtJS.

Actual Behavior

Get compilation error:

 ERROR  Failed to compile with 2 errors

This dependency was not found:
                              
* fs in ./node_modules/balena-settings-client/build/settings.js, ./node_modules/balena-settings-storage/build/node-storage.js
                              
To install it, you can run: npm install --save fs

Steps to Reproduce the Problem

  1. npm i -S balena-sdk
  2. Add to Nuxt app page: pages/index.vue:
<script>
export default {
  mounted() {
    if (process.client) {
      const { getSdk } = require('balena-sdk/es2015')
    }
  }
}
</script>
  1. Get error on console.

Specifications

@thgreasi
Copy link
Member

Hi,
Thanks for raising this. It is indeed an issue with how module bundlers analyze the sources and take into account even branches that never run in browsers.
The simplest workaround is to use the pre-bundled balena-sdk, which you can find in ~/es2015/balena-browser.min.js (or even use a CDN like https://unpkg.com/balena-sdk@15.53.0/es2015/balena-browser.min.js).

In case you prefer using ES6 module imports, a more involved fix for this is to edit your nuxt.config.js like:

export default {
    build: {
        extend(config, {}) {
            config.node = {
                fs: 'empty',
                path: 'empty',
                balena-settings-client: 'empty',
                node-localstorage: 'empty',
            }
        }
    }
}

For sure though we do need to change the SDK's structure so that such workarounds are not necessary,

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

2 participants