paulmillr / es6-shim

ECMAScript 6 compatibility shims for legacy JS engines
http://paulmillr.com
MIT License
3.11k stars 387 forks source link

Cannot convert a Symbol value to a string #361

Closed chatbox-inc-hoge closed 8 years ago

chatbox-inc-hoge commented 8 years ago

es6-loader 経由でwebpackを実行すると、下記エラーが起きます。

TypeError: Cannot convert a Symbol value to a string
    at RegExp.test (native)
    at assertNotName (/Users/mkkn/mine/chatbox.site/node_modules/es6-loader/node_modules/es6-module-transpiler/dist/es6-module-transpiler.js:200:16)
    at Function.defineProperty (/Users/mkkn/mine/chatbox.site/node_modules/es6-loader/node_modules/es6-module-transpiler/dist/es6-module-transpiler.js:256:7)
    at defineProperty (/Users/mkkn/mine/chatbox.site/node_modules/es6-loader/node_modules/es6-transpiler/node_modules/es6-shim/es6-shim.js:86:14)
    at addIterator (/Users/mkkn/mine/chatbox.site/node_modules/es6-loader/node_modules/es6-transpiler/node_modules/es6-shim/es6-shim.js:286:5)
    at /Users/mkkn/mine/chatbox.site/node_modules/es6-loader/node_modules/es6-transpiler/node_modules/es6-shim/es6-shim.js:730:3
    at /Users/mkkn/mine/chatbox.site/node_modules/es6-loader/node_modules/es6-transpiler/node_modules/es6-shim/es6-shim.js:22:22
    at Object.<anonymous> (/Users/mkkn/mine/chatbox.site/node_modules/es6-loader/node_modules/es6-transpiler/node_modules/es6-shim/es6-shim.js:27:2)
    at Module._compile (module.js:460:26)
    at Object.Module._extensions..js (module.js:478:10)
    at Module.load (module.js:355:32)
    at Function.Module._load (module.js:310:12)
    at Module.require (module.js:365:17)
    at require (module.js:384:17)
    at Object.<anonymous> (/Users/mkkn/mine/chatbox.site/node_modules/es6-loader/node_modules/es6-transpiler/build/es5/es6-transpiler.js:5:1)
    at Module._compile (module.js:460:26)
    at Object.Module._extensions..js (module.js:478:10)
    at Module.load (module.js:355:32)
    at Function.Module._load (module.js:310:12)
    at Module.require (module.js:365:17)
    at require (module.js:384:17)
    at Object.<anonymous> (/Users/mkkn/mine/chatbox.site/node_modules/es6-loader/index.js:10:15)
    at Module._compile (module.js:460:26)
    at Object.Module._extensions..js (module.js:478:10)
    at Module.load (module.js:355:32)
    at Function.Module._load (module.js:310:12)
    at Module.require (module.js:365:17)
    at require (module.js:384:17)
    at DependenciesBlock.loadPitch (/Users/mkkn/mine/chatbox.site/node_modules/webpack/node_modules/webpack-core/lib/NormalModuleMixin.js:193:17)
    at DependenciesBlock.doBuild (/Users/mkkn/mine/chatbox.site/node_modules/webpack/node_modules/webpack-core/lib/NormalModuleMixin.js:241:4)

このエラーは

https://github.com/paulmillr/es6-shim/blob/master/es6-shim.js#L278

var $iterator$ = Type.symbol(Symbol.iterator) ? Symbol.iterator.toString() : '_es6-shim iterator_'

とすると治ったのですが、これってマージされますか?

node v0.12.7 es6-shim version: "0.33.3",

martinheidegger commented 8 years ago

I was asked to translate this to english:

When using es6-loader with webpack the following error occurred:

TypeError: Cannot convert a Symbol value to a string
    at RegExp.test (native)
    at assertNotName (/Users/mkkn/mine/chatbox.site/node_modules/es6-loader/node_modules/es6-module-transpiler/dist/es6-module-transpiler.js:200:16)
    at Function.defineProperty (/Users/mkkn/mine/chatbox.site/node_modules/es6-loader/node_modules/es6-module-transpiler/dist/es6-module-transpiler.js:256:7)
    at defineProperty (/Users/mkkn/mine/chatbox.site/node_modules/es6-loader/node_modules/es6-transpiler/node_modules/es6-shim/es6-shim.js:86:14)
    at addIterator (/Users/mkkn/mine/chatbox.site/node_modules/es6-loader/node_modules/es6-transpiler/node_modules/es6-shim/es6-shim.js:286:5)
    at /Users/mkkn/mine/chatbox.site/node_modules/es6-loader/node_modules/es6-transpiler/node_modules/es6-shim/es6-shim.js:730:3
    at /Users/mkkn/mine/chatbox.site/node_modules/es6-loader/node_modules/es6-transpiler/node_modules/es6-shim/es6-shim.js:22:22
    at Object.<anonymous> (/Users/mkkn/mine/chatbox.site/node_modules/es6-loader/node_modules/es6-transpiler/node_modules/es6-shim/es6-shim.js:27:2)
    at Module._compile (module.js:460:26)
    at Object.Module._extensions..js (module.js:478:10)
    at Module.load (module.js:355:32)
    at Function.Module._load (module.js:310:12)
    at Module.require (module.js:365:17)
    at require (module.js:384:17)
    at Object.<anonymous> (/Users/mkkn/mine/chatbox.site/node_modules/es6-loader/node_modules/es6-transpiler/build/es5/es6-transpiler.js:5:1)
    at Module._compile (module.js:460:26)
    at Object.Module._extensions..js (module.js:478:10)
    at Module.load (module.js:355:32)
    at Function.Module._load (module.js:310:12)
    at Module.require (module.js:365:17)
    at require (module.js:384:17)
    at Object.<anonymous> (/Users/mkkn/mine/chatbox.site/node_modules/es6-loader/index.js:10:15)
    at Module._compile (module.js:460:26)
    at Object.Module._extensions..js (module.js:478:10)
    at Module.load (module.js:355:32)
    at Function.Module._load (module.js:310:12)
    at Module.require (module.js:365:17)
    at require (module.js:384:17)
    at DependenciesBlock.loadPitch (/Users/mkkn/mine/chatbox.site/node_modules/webpack/node_modules/webpack-core/lib/NormalModuleMixin.js:193:17)
    at DependenciesBlock.doBuild (/Users/mkkn/mine/chatbox.site/node_modules/webpack/node_modules/webpack-core/lib/NormalModuleMixin.js:241:4)

This error would be fixed by changing the following line:

https://github.com/paulmillr/es6-shim/blob/master/es6-shim.js#L278

to

var $iterator$ = Type.symbol(Symbol.iterator) ? Symbol.iterator.toString() : '_es6-shim iterator_'

Would that be a problem to merge?

ljharb commented 8 years ago

No, that will not fix it. By the spec, stringifying a Symbol throws in all but two cases. The only ways to stringify a symbol safely is String(Symbol()), or Symbol().toString(). This is a node 0.12 bug specifically, where String(x) throws (however, Symbol.prototype.toString.call(x) doesn't, as you pointed out).

The entire purpose of symbols is to be used as non-string object keys - so why would we want to stringify it?

This node 0.12 v8 bug is impossible to fix in JS-land, and is fixed in io.js and node v4.0 and later.

It seems that es6-module-transpiler is attempting to stringify a symbol, and is unaware of this node bug - please file the issue there, as that's something they need to fix.