Monday, 27 September 2021

SvelteKit cannot import Onboard.js

I am working on a SvelteKit project and have installed Onboard.js:

I am using the pnpm package manager, but it shouldn't make a difference:

pnpm install bnc-onboard
// __layout.svelte
import Onboard from "bnc-onboard";

When I start my development server, I get the following module resolution errors (not all have been included):

pnpm run dev

enter image description here

How can I fix this?

Edit: I tried following these rollup instructions. Since SvelteKit uses Vite, which is based on Rollup, I tried adding the following to svelte.config.js:

import resolve from '@rollup/plugin-node-resolve'
import commonjs from '@rollup/plugin-commonjs'
import json from '@rollup/plugin-json'
import nodePolyfills from 'rollup-plugin-node-polyfills'

// ...

export default {
  // ...
  kit: {
    // ...
    vite: {
       plugins: [
            json(),
            resolve({
                browser: true,
                preferBuiltins: true
            }),
            commonjs({
                namedExports: {
                    "u2f-api": ["sign", "isSupported"]
                },
            }),
            nodePolyfills(),
        ],
    },
  },
};

This did not help. I am getting the exact same error.

Edit 2: It appears the bnc-onboard package never installed correctly in the first place. I made another question about this here, and I'll update this question once I fix that.

Edit 3: I got the above solved. Now I'm getting this slightly different error:

enter image description here



from SvelteKit cannot import Onboard.js

No comments:

Post a Comment