TypeError: Cannot read property 'prototype' of undefined
at ../../../../node_modules/c3/c3.js:2720:30
at ../../../../node_modules/c3/c3.js:3263:3
at Object.<anonymous>.CLASS.target (../../../../node_modules/c3/c3.js:2:82)
at Object.<anonymous> (../../../../node_modules/c3/c3.js:5:2)
์ด๋ค
window.SVGPathElement.prototype.createSVGPathSegClosePath = function () {
์ด๊ฒ์ ์ด๋์ ์ ๊ณ ํด์ผ ํ ์ง ์ ๋ชจ๋ฅด๊ฒ ์ต๋๋ค. ๋๋ด, jsdom, ์ฌ๊ธฐ?
๋ํ ์ด ์ค๋ฅ๊ฐ ๋ฐ์ํฉ๋๋ค. c3 ๋๋ jsdom์ ๋ฌธ์ ๊ฐ ์๋์ง ํ์คํ์ง ์์ต๋๋ค.
๋น npm ํ๋ก์ ํธ๋ฅผ ๋ง๋ญ๋๋ค. ๊ทธ๋ฐ ๋ค์ ๋ค์์ ์๋ํ์ญ์์ค.
npm i -S c3 jsom
node -e "var JSDOM = require('jsdom').JSDOM; global.window = new JSDOM().window; require('c3');"
์ฐ์ถ:
/home/herinson/example/node_modules/c3/c3.js:2720
window.SVGPathElement.prototype.createSVGPathSegClosePath = function () {
^
TypeError: Cannot read property 'prototype' of undefined
at /home/herinson/example/node_modules/c3/c3.js:2720:30
at /home/herinson/example/node_modules/c3/c3.js:3263:3
at CLASS.target (/home/herinson/example/node_modules/c3/c3.js:2:82)
at Object.<anonymous> (/home/herinson/example/node_modules/c3/c3.js:5:2)
at Module._compile (module.js:573:30)
at Object.Module._extensions..js (module.js:584:10)
at Module.load (module.js:507:32)
at tryModuleLoad (module.js:470:12)
at Function.Module._load (module.js:462:3)
at Module.require (module.js:517:17)
์ด์ ์๋ ์ด ์ค๋ฅ๊ฐ ๋ฐ์ํ์ง ์์์ต๋๋ค.
์๋ง๋ ์ด๊ฒ๊ณผ ๊ด๋ จ์ด ์์ ๊ฒ์
๋๋ค https://github.com/tmpvar/jsdom/pull/1445
SVGPathElement ์์ฑ์ ์กฐ๋กฑํ ์ ์๋ค๊ณ ์๊ฐํ์ญ๋๊น?
๋๋ ๋ถ๋ช ํ jsdom์ ๋ถ์์ ํ SVG ๊ตฌํ์ ๋ฌธ์ ๊ฐ ์๋ค๊ณ ์๊ฐํฉ๋๋ค.
๊ทธ๋ฌ๋ ์ข์ ํด๊ฒฐ ๋ฐฉ๋ฒ์ ๋ฌด์์ ๋๊น? jsdom/jest์ ์ข ์์ฑ์ผ๋ก C3๊ฐ ์๋ ํ๋ก์ ํธ๋ฅผ ๋จ์ ํ ์คํธํ ์ ์๊ธฐ๋ฅผ ์ํ์ง๋ง ์ด๊ฒ์ ๊ฝค ํฐ ์ฐจ๋จ๊ธฐ์ ๋๋ค. ์ค์ ๋ก C3 ๊ธฐ๋ฅ ์ค ์ด๋ค ๊ฒ๋ ๋จ์ ํ ์คํธํ ํ์๊ฐ ์์ผ๋ฏ๋ก ์คํ ์ ์ ๊ฑฐํ ์ ์์ ๊ฒ ๊ฐ์ต๋๋ค...
SVGPathElement ์์ฑ์ ์กฐ๋กฑํ ์ ์๋ค๊ณ ์๊ฐํ์ญ๋๊น?
๊ทธ๊ฒ์ด ๊ฐ๋ฅํ ํด๊ฒฐ์ฑ ์ด ๋ ๊ฒ์ ๋๋ค.
๋๋ c3๋ฅผ ์ฌ์ฉํ๊ณ ์์ง๋ ์์ง๋ง ์๋ง๋ ๋ด ํ๋ก์ ํธ์ ๋ค๋ฅธ ํจํค์ง๋ ์ฌ์ฉํ๊ณ ์์ ๊ฒ์
๋๋ค.
๋ด ํ
์คํธ๋ ๋ง์ ์ข
์์ฑ์ ์
๋ฐ์ดํธํ ๋๊น์ง ์ ๋๋ก ์๋ํ์ต๋๋ค. ๋๋ ์ฌ์ ํ c3๋ฅผ ์ฌ์ฉํ๋ ์ข
์์ฑ์ ํ์
ํ๋ ค๊ณ ๋
ธ๋ ฅํ๊ณ ์์ต๋๋ค.
์ถ์ : jsdom์ ๋ด ํ
์คํธ ํ์ผ์ ์์ต๋๋ค.
๊ทธ๊ฒ์ ๋ฐ๊ฒฌ! ๋ ์นด๋ก์ด-js๋ฅผ v3.4.1๋ก ๋กค๋ฐฑํ๋ฉด ๋ฌธ์ ๊ฐ "ํด๊ฒฐ"๋์์ต๋๋ค. ์ต์ ๋ฒ์ ์ 4.0.0์ ๋๋ค.
๋์ ๊ฐ์ ๋ฌธ์ ๊ฐ ์๋ ์ฌ๋์ ๊ฒฝ์ฐ Keen์ ๊ธฐ๋ณธ ํจํค์ง๋ฅผ 3๊ฐ์ ๊ฐ๋ณ ํจํค์ง๋ก ๋๋๊ธฐ๋ก ๊ฒฐ์ ํ์ต๋๋ค. https://github.com/keen/keen-js/releases/tag/v4.0.0
๋ฌธ์ ๋ sharp-dataviz.js๊ฐ c3.js๋ฅผ ์ฌ์ฉํ๋ค๋ ๊ฒ์ ๋๋ค. ๋๋ ์ฐจํธ๋ฅผ ์ฌ์ฉํ์ง ์๊ธฐ ๋๋ฌธ์ ๋์ ๊ฒฝ์ฐ ํด๊ฒฐ์ฑ ์ ์๋ฆฌํ ์ถ์ ์ ์ค์นํ๊ณ ์๋ฆฌํ js๋ฅผ ์ ๊ฑฐํ๋ ๊ฒ์ ๋๋ค.
jest ๋ฅผ ์ฌ์ฉํ์ฌ ๋์ผํ ๋ฌธ์ ์ ์ง๋ฉดํ๊ณ ์์ผ๋ฉฐ
TypeError: Cannot read property 'prototype' of undefined
at node_modules/c3/c3.js:2806:30
at node_modules/c3/c3.js:3349:3
ํ ๋ฒํธ์ ์ฝ๊ฐ์ ์ฐจ์ด์ , ์๋ง๋ ์ผ๋ถ ๋น๋ ๊ด๋ จ(์ ๋ c3 ๋ฒ์ ์ ์ฌ์ฉํ๊ณ ์์ต๋๋ค: 0.4.18)
์
๋ฐ์ดํธ: window.SVGPathElement.prototype.createSVGPathSegClosePath = function ()
๋ ์ฌ๊ธฐ์๋ ์์ต๋๋ค.
์ถ์ : ๋ธ๋ผ์ฐ์ ์์ ์๋ฒฝํ๊ฒ ์๋ํฉ๋๋ค. ๋๋ด์ผ๋ก ์ด ์ค๋ฅ๊ฐ ๋ฐ์ํฉ๋๋ค.
์ฌ๊ธฐ๋ ๋ง์ฐฌ๊ฐ์ง์ ๋๋ค. ๋๋ ์ด๊ฒ์ด https://github.com/tmpvar/jsdom/issues/1423์ ๋ํ ๋ต์ด๋ผ๊ณ ๋ฏฟ์ต๋๋ค.
@brandonros
jest ํ
์คํธ ์ผ์ด์ค์์ c3 ๊ธฐ๋ฅ์ด ํ์ํ์ง ์๋ค๋ฉด SVGPathElement๋ฅผ ๋๋ฏธ ๊ฐ์ฒด๋ก ๊ต์ฒดํ๋ ๊ฒ์ด ๊ด์ฐฎ๋ค๊ณ ์๊ฐํฉ๋๋ค.
์๋์ ๊ฐ์ด window.SVGPathElement๋ฅผ ๋๋ฏธํํ์ฌ ๋ ธ๋ ํ๊ฒฝ์์ c3.js๋ฅผ ์๊ตฌํ ์ ์์์ต๋๋ค.
var JSDOM = require('jsdom').JSDOM;
global.window = new JSDOM().window;
window.SVGPathElement = function () {};
console.log(require('c3')); // => no error!
@fernandes ์ ๋ ๋น์ทํ ๋ฌธ์ ์ ์ง๋ฉดํด ์์ต๋๋ค. ํด๊ฒฐ ๋ฐฉ๋ฒ์ ์ฐพ์์ต๋๊น?
์๋ @esonmez , ๋๋ ...
jsdom์ด SVG๋ฅผ ๊ตฌํํ์ง ์๋๋ค๋ ๊ฒ์ ์กฐ์ฌํ๊ธฐ ๋๋ฌธ์ ํ ์คํธ(jdsom์ ์ฌ์ฉํ๋)์์ c3๋ฅผ ์ฌ์ฉํ ์ ์์ต๋๋ค. ๊ฐ๋ฅํ ํ c3 ๊ตฌ์ฑ ์์๋ฅผ ๋ถ๋ฆฌํ๊ณ ์ด ํ ์คํธ๋ฅผ ์ค๋จํ์ต๋๋ค.
@fernandes ์๊ฒ ์ต๋๋ค. ์กฐ๊ธ ๋ ๊ฐ์ง๊ณ ๋์๊ณ c3์ ์กฐ๋กฑํ์ฌ ์ค๋ ์ท ํ ์คํธ๋ฅผ ์คํํ ์ ์์์ต๋๋ค.
// __mocks__/c3.js
module.exports = () => 'c3';
๊ทธ๋ฐ ๋ค์ ๋ด package.json
์ Jest ๊ตฌ์ฑ ๋ถ๋ถ์์ :
"moduleNameMapper": {
"c3": "<rootDir>/__mocks__/c3.js",
}
ํํํ ํฅ๋ฏธ๋กญ๋ค์. ํ์ ๊ณต์ ํด ์ฃผ์ ์ ๊ฐ์ฌํฉ๋๋ค. ํ๋ก์ ํธ์ ์ ์ฉํ ์์ ์ ๋๋ค. ๊ฐ์ฌํฉ๋๋ค!
@esonmez ์ ์ ์์ ์ฌ์ฉํ์ฌ ์ด ๋ฌธ์ ๋ฅผ ํด๊ฒฐํ๊ฒ ๋์ด
Out of the box, Create React App only supports overriding these Jest options:
โข collectCoverageFrom
โข coverageReporters
โข coverageThreshold
โข snapshotSerializers.
These options in your package.json Jest configuration are not currently supported by Create React App:
โข moduleNameMapper
If you wish to override other Jest options, you need to eject from the default setup. You can do so by running npm run eject but remember that this is a one-way operation. You may also file an issue with Create React App to discuss supporting more options out of the box.
ํ๋ง๋๋ก ์ค๋ง์ค๋ฝ์ต๋๋ค. ์ด์จ๋ ์ฐ๋ฆฌ์ jest ์ค์ ํ์ผ์์ @kt3k ๊ฐ ํ๋ ๊ฒ์ฒ๋ผ ์กฐ๋กฑํ ์ ์์์ต๋๋ค.
global.SVGPathElement = function () {}
๊ทธ๋ฆฌ๊ณ ๊ทธ๊ฒ์ ๋งค๋ ฅ์ฒ๋ผ ์๋ํ์ต๋๋ค. ๋ชจ๋ ๋์์ฃผ์ ์ ๊ฐ์ฌํฉ๋๋ค!
C3.js์ ๋ค๋ฅธ ๋ผ์ด๋ธ๋ฌ๋ฆฌ(react, vuejs, ..) ๊ฐ์ ์ํธ ์์ฉ๊ณผ ๊ด๋ จ๋ ์ง๋ฌธ์ https://groups.google.com/forum/#!forum/c3js ์์ Google ๊ทธ๋ฃน์ ์ฌ์ฉ
๊ฐ์ฌํฉ๋๋ค!
๊ฐ์ฅ ์ ์ฉํ ๋๊ธ
@fernandes ์๊ฒ ์ต๋๋ค. ์กฐ๊ธ ๋ ๊ฐ์ง๊ณ ๋์๊ณ c3์ ์กฐ๋กฑํ์ฌ ์ค๋ ์ท ํ ์คํธ๋ฅผ ์คํํ ์ ์์์ต๋๋ค.
๊ทธ๋ฐ ๋ค์ ๋ด
package.json
์ Jest ๊ตฌ์ฑ ๋ถ๋ถ์์ :