Hi all, I'm writing a multiplatform library. Curre...
# javascript
g
Hi all, I'm writing a multiplatform library. Currently, working on JS implementation. I just wrote a simple test and it worked (node), but fails in browser. I'm using third-party library and it looks like I need a polyfill for
buffer
. The error I'm getting:
Copy code
Buffer is not defined
calculateChecksum@/run/user/1000/_karma_webpack_946395/commons.js
build.gradle.kts:
Copy code
js(IR) {
    moduleName = "kotlin-wallet-sdk"
    nodejs()
    browser {
      testTask { useKarma { useFirefox() } }
    }
    binaries.library()
  }
I tried adding this to webpack.config.d:
Copy code
module.exports = {
    resolve: {
        fallback: {
            buffer: require.resolve('buffer'),
        },
    },
};
But it didn't work. I noticed that karma.js uses webpack config object, so i tried to set
Copy code
config.module.exports = {
    resolve: {
        fallback: {
            buffer: require.resolve('buffer'),
        },
    },
};
But it gives me an error
Copy code
ValidationError: Invalid configuration object. Webpack has been initialized using a configuration object that does not match the API schema.
 - configuration.module has an unknown property 'exports'. These properties are valid:
   object { defaultRules?, exprContextCritical?, exprContextRecursive?, exprContextRegExp?, exprContextRequest?, generator?, noParse?, parser?, rules?, strictExportPresence?, strictThisContextOnImports?, unknownContextCritical?, unknownContextRecursive?, unknownContextRegExp?, unknownContextRequest?, unsafeCache?, wrappedContextCritical?, wrappedContextRecursive?, wrappedContextRegExp? }
Any ideas/recommendations? Setting webpack version to 4 resolves this issue, but I'm pretty sure there is a proper way of fixing it without rollbacking to older version of the webpack