svg-sprite-loader with Angular 8 custom webpack config

谁说胖子不能爱 提交于 2021-02-10 20:29:38

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/58520617/svg-sprite-loader-with-angular-8-custom-webpack-config

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!