I am trying to use svg-sprite-loader package (to create a svg sprite) with my Angular 8 project using custom webpack config.
I am using below custom config:
const SpriteLoaderPlugin = require('svg-sprite-loader/plugin');
module.exports = {
module: {
rules: [
{
test: /\.(svg)$/,
loader: 'svg-sprite-loader',
options: {
spriteFilename: './src/assets/svg/combinedicons.svg',
runtimeCompat: true,
},
},
],
},
plugins: [
new SpriteLoaderPlugin({
plainSprite: true,
}),
],
};
I am getting following error while running ng build:
Cannot find module 'webpack/package.json' Error: Cannot find module 'webpack/package.json'
I am not able to identify where the issue is, is it with my config or the package itself.
You might need to install Webpack as an explicit dependency via npm i -D webpack
.
Or you might have 2 different versions of Webpack installed.
Run npm ls webpack
.
You should see something like this:
user$ npm ls webpack
@my-app /Users/user/my-app
├─┬ @angular-devkit/build-angular@0.13.9
│ └── webpack@4.29.0 deduped
└── webpack@4.29.0
If you have different versions of webpack try npm installing a version of webpack that matches that of the @angular-devkit/build-angular
dependency.
If you have the CLI installed globally it's also worth checking if you have multiple versions of Webpack installed globally.
I believe you can run npm ls -g webpack
.