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

Segmentation fault (core dumped) #1596

Closed
oliverfindl opened this issue Oct 1, 2021 · 16 comments
Closed

Segmentation fault (core dumped) #1596

oliverfindl opened this issue Oct 1, 2021 · 16 comments
Labels

Comments

@oliverfindl
Copy link

Describe the bug
I upgraded SVGO from version 2.3.1 to 2.7.0 and got error Segmentation fault (core dumped). I tried multiple versions of SVGO and I'm encountering this issue only in version 2.7.0. Version 2.6.1 works fine. During upgrade process I changed my svgo.config.js from:

"use strict";

const { extendDefaultPlugins } = require("svgo");

module.exports = {
	plugins: extendDefaultPlugins([
		{
			name: "removeViewBox",
			active: false,
		},
	]),
};

To:

"use strict";

module.exports = {
	plugins: [
		{
			name: "preset-default",
			params: {
				overrides: {
					removeViewBox: false,
				},
			},
		},
	],
};

To Reproduce
Steps to reproduce the behavior:
I'm encountering this issue using svgo-loader for webpack. My webpack module rule:

"use strict";

module.exports = {
	// ...
	module: {
		rules: [
			// ...
			{
				test: /\.svg$/i,
				exclude: /node_modules/,
				use: [
					{
						loader: "url-loader",
						options: {
							esModule: false,
						},
					},
					"svgo-loader",
				],
			},
			// ...
		],
	},
	// ...
};

Expected behavior
No errors.

Screenshots
N/A

Desktop (please complete the following information):

  • SVGO Version: 2.7.0
  • NodeJs Version: 16.10.0
  • OS: Pop!_OS 20.04 LTS

Additional context
N/A

@oliverfindl oliverfindl added the bug label Oct 1, 2021
@TrySound
Copy link
Member

TrySound commented Oct 1, 2021

@oliverfindl Do you have any svg files examples?

@oliverfindl
Copy link
Author

Hello @TrySound,

I'm using slightly modified SVG icons from Chromium project.

chromium_icons.zip

Thanks.

@oliverfindl
Copy link
Author

Hello @TrySound,

I also tried my project on different PC, but got same error.

  • SVGO Version: 2.7.0
  • NodeJs Version: 14.17.6
  • OS: Ubuntu 16.04.7 LTS

Here are some logs.

Terminal output:

> npx rimraf dist/**/*.min.{js,css} && npx webpack --progress --color

10% building 0/1 entries 39/39 dependencies 10/20 modulesSegmentation fault (core dumped)
npm ERR! code ELIFECYCLE
npm ERR! errno 139
npm ERR! project@0.1.0 webpack: `npx rimraf dist/**/*.min.{js,css} && npx webpack --progress --color`
npm ERR! Exit status 139
npm ERR! 
npm ERR! Failed at the project@0.1.0 webpack script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/oliver/.npm/_logs/2021-10-01T22_17_05_669Z-debug.log

Stack trace from debug log:

13 verbose stack Error: project@0.1.0 webpack: `npx rimraf dist/**/*.min.{js,css} && npx webpack --progress --color`
13 verbose stack Exit status 139
13 verbose stack     at EventEmitter.<anonymous> (/usr/lib/node_modules/npm/node_modules/npm-lifecycle/index.js:332:16)
13 verbose stack     at EventEmitter.emit (events.js:400:28)
13 verbose stack     at ChildProcess.<anonymous> (/usr/lib/node_modules/npm/node_modules/npm-lifecycle/lib/spawn.js:55:14)
13 verbose stack     at ChildProcess.emit (events.js:400:28)
13 verbose stack     at maybeClose (internal/child_process.js:1055:16)
13 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:288:5)

There are no mentions about SVGO, but downgrading to v2.6.1 solves this issue for me.

Thanks.

@TrySound
Copy link
Member

TrySound commented Oct 1, 2021

Try to pass configFile: false and specify whole config in loader options

@oliverfindl
Copy link
Author

Hello @TrySound,

I got it somehow fixed on both my PCs. I tried:

First PC:

  • renamed svgo.config.js to _svgo.config.js
  • set configFile: false
  • set plugin options same as in config file
  • worked
  • checkouted all changes back
  • also worked

Second PC:

  • renamed svgo.config.js to _svgo.config.js
  • no changes to webpack config file
  • worked
  • renamed _svgo.config.js back to svgo.config.js
  • also worked

I have no idea where this issue was coming from. I purged node_modules and package-lock.json multiple times. I also tried multiple configurations (multiple versions of SVGO config file), so that rules out some issue with incorrectly saved file.

Thanks.

@TrySound
Copy link
Member

TrySound commented Oct 1, 2021

Thanks. Looks like using dynamic import for config loading is buggy. This looks related nodejs/node#35889

@oliverfindl
Copy link
Author

Closing this issue as resolved.

Thanks.

@TrySound
Copy link
Member

TrySound commented Oct 2, 2021

Not quite resolved. We just found workaround.

@TrySound TrySound reopened this Oct 2, 2021
@oliverfindl
Copy link
Author

Hello @TrySound,

I was looking into commit 7111c52, responsible for ESM support and you could preserve previous (working) approach in case of .cjs config file in importConfig function.

svgo/lib/svgo-node.js

Lines 16 to 40 in 7601b17

const importConfig = async (configFile) => {
let config;
try {
// dynamic import expects file url instead of path and may fail
// when windows path is provided
const { default: imported } = await import(pathToFileURL(configFile));
config = imported;
} catch (importError) {
// TODO remove require in v3
try {
config = require(configFile);
} catch (requireError) {
// throw original error if es module is detected
if (requireError.code === 'ERR_REQUIRE_ESM') {
throw importError;
} else {
throw requireError;
}
}
}
if (config == null || typeof config !== 'object' || Array.isArray(config)) {
throw Error(`Invalid config file "${configFile}"`);
}
return config;
};

E.g.:

let config;
if (path.extname(configFile) === ".cjs") {
	config = require(configFile);
} else {
	// try ... catch
}

This might solve this issue at least for non-ESM users. Unfortunately, its not a solution, just a workaround.

Thanks.

@oliverfindl
Copy link
Author

Hello @TrySound,

I encountered this issue again. It took up 4 cycles of renaming svgo.config.js back and forth to fix it. This looks kinda random. I'm going back to v2.6.1 for now.

Thanks.

TrySound added a commit that referenced this issue Oct 5, 2021
Ref #1596

At the moment dynamic import may randomly fail with segfault.
To workaround this for some users .cjs extension is loaded
exclusively with require.
TrySound added a commit that referenced this issue Oct 29, 2021
Ref #1596

At the moment dynamic import may randomly fail with segfault.
To workaround this for some users .cjs extension is loaded
exclusively with require.
@TrySound
Copy link
Member

TrySound commented Nov 2, 2021

@TrySound TrySound closed this as completed Nov 2, 2021
@oliverfindl
Copy link
Author

Thanks.

@TrySound
Copy link
Member

TrySound commented Nov 2, 2021

Does it work for you?

@oliverfindl
Copy link
Author

Tried to build my project a few times without any issue. If I will encounter this issue again, I will report it here. Thanks.

@clxandstuff
Copy link

Hi.
I encountered the same issue on version 3.0.0 and used the config rename method. I will try to prepare a reproduction case.

@xusai2014
Copy link

xusai2014 commented Dec 12, 2022

svg parse the config file throw the exception
Module resolution depends on the filename '.cjs'. so you need renamed to .cjs when using module.export.

`
svgo.config.js

svgo.config.cjs
`

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

No branches or pull requests

4 participants