I have an angular2 typescript webapp which is build with webpack. I am trying to integrate solclientjs into it, but I get the exception below
solclientjs-exports.js:34 Uncaught Error: Cannot find module "."
at webpackMissingModule (solclientjs-exports.js:34)
at load (solclientjs-exports.js:34)
at loadProduction (solclientjs-exports.js:44)
at new loader (solclientjs-exports.js:47)
at Object. (solclientjs-exports.js:72)
at webpack_require (bootstrap 79a17da…:52)
at Object. (home.component.ts:8)
at webpack_require (bootstrap 79a17da…:52)
at Object. (app.ts:17)
at webpack_require (bootstrap 79a17da…:52)
Can you please advise?
Using exports-loader will enable you to package the library with Webpack.
Here's a sample webpack.config.js
after exports-loader is used.
const path = require('path');
const solclientjs = path.resolve(__dirname, 'path/to/solclientjs-10.0.0/lib/solclient.js');
module.exports = {
resolve: {
alias: {
solclientjs$: solclientjs
}
},
module: {
rules: [
{
test: require.resolve(solclientjs),
use: 'exports-loader?window.solace'
}
]
}
}
A couple of things to note:
You need to use the browser version instead of the node version for Webpack. Packing the Node version of the library for use in the browser isn't supported and won't work.
For compatibility reasons, the browser version of the library is shipped so that it can be directly included with a <script> tag in a file. For browsers, it's highly recommended that the library be loaded with it. Examples can be found here.