Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: Cannot read property 'source' of undefined #311

Closed
GrzegorzZajac000 opened this issue Sep 24, 2018 · 6 comments
Closed

TypeError: Cannot read property 'source' of undefined #311

GrzegorzZajac000 opened this issue Sep 24, 2018 · 6 comments

Comments

@GrzegorzZajac000
Copy link

GrzegorzZajac000 commented Sep 24, 2018

Do you want to request a feature, report a bug or ask a question?
Report a bug
What is the current behavior?
Error in webpack build
What is the expected behavior?
Working webpack build

Please tell us about your environment:

  • Node.js version: v8.11.1
  • webpack version: v4.19.1
  • svg-sprite-loader version: v4.1.1
  • OS type & version: MacOS 10.13.6

Other information (e.g. detailed explanation, stacktraces, related issues, suggestions how to fix, links for us to have context, eg. stackoverflow, gitter, etc)

Webpack config

...
                         {
				test: /static\/images\/svg-sprites\/.*\.svg$/,
				use: [
					{
						loader: 'svg-sprite-loader',
						options: {
							esModule: false,
							extract: true,
							spriteFilename: 'images/sprites.svg',
							publicPath: isProd ? config.publicPathProd : '/'
						}
					},
					{
						loader: 'svgo-loader',
						options: {
							plugins: [
								{ removeTitle: true },
								{ removeDoctype: true },
								{ removeXMLProcInst: true },
								{ removeComments: true },
								{ removeMetadata: true },
								{ convertColors: {
									shorthex: true
								}},
								{ convertPathData: false },
								{ minifyStyles: true }
							]
						}
					}
				]
			}
...
  • plugin with plainSprite: true

Error:

ERROR in   TypeError: Cannot read property 'source' of undefined
  
  - plugin.js:220 Object.keys.reduce
    [www-v2]/[svg-sprite-loader]/lib/plugin.js:220:52
  
  - Array.reduce
  
  - plugin.js:219 SVGSpritePlugin.beforeHtmlGeneration
    [www-v2]/[svg-sprite-loader]/lib/plugin.js:219:48
  
  - plugin.js:97 compilation.hooks.htmlWebpackPluginBeforeHtmlGeneration.tapAsync
    [www-v2]/[svg-sprite-loader]/lib/plugin.js:97:54
  
  
  - new Promise
  
  
  - Hook.js:154 AsyncSeriesWaterfallHook.lazyCompileHook
    [www-v2]/[tapable]/lib/Hook.js:154:20
  
  - index.js:673 
    [www-v2]/[html-webpack-plugin]/index.js:673:47
  
  - index.js:165 Promise.resolve.then.then.then.then.compilationResult
    [www-v2]/[html-webpack-plugin]/index.js:165:36
@kisenka
Copy link
Contributor

kisenka commented Sep 27, 2018

Could you please create repo with minimal setup to demonstrate a problem (package.json, webpack config, SVG image and piece of your code). If you don't want to create a repository - you can create a gist with multiple files.

@rmunch
Copy link

rmunch commented Oct 9, 2018

I'm also running into this issue. I think the error happens in the following scenario:

  • Using html-webpack-plugin
  • Option extract is enabled
  • Option publicPath is set

I uploaded a demo repo at https://github.com/rmunch/svg-sprite-loader-source-bug - run npm install, then npx webpack --config webpack.config.js --mode production

Thanks!

@xie007
Copy link

xie007 commented Jan 20, 2019

try this:

{
                        loader: 'svg-sprite-loader',
                        options: {
                            extract: true,
                            //publicPath: 'asset/'
                        }
                    }

publicPath have a bug, default value is 'sprite.svg', Unable to pass path parameters.

my version is "svg-sprite-loader": "^4.1.3"

@kisenka @rmunch @GrzegorzZajac000

@Eli-Black-Work
Copy link

@GrzegorzZajac000 Can this be closed?

@GrzegorzZajac000
Copy link
Author

@Bosch-Eli-Black yes ;)

@Eli-Black-Work
Copy link

@GrzegorzZajac000 Haha, thanks ^_^

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants