webpack character encoding

David Ford
1 min readNov 18, 2016

--

I have a React app that is working fine in dev mode. But when I ran it in production mode, these crazy characters started showing up. They sort of look like an uppercase A:

I was able to isolate the problem to webpack’s devtool config setting.

For dev mode, I was using this setting:

devtool: 'eval-source-map'              //dev-mode only

But for production, I was using this setting:

devtool: 'cheap-module-source-map'       //prod-mode only

The problem only happens when using webpack’s -p plus the cheap-module-source-map option.

I’m not sure exactly where the problem lies, but since it happens only in production mode and not in dev mode, I’m going to blame webpack.

But anyway, this is what I did to fix the problem, I added a charset attribute to my script tag like so:

<script 
type=”text/javascript”
src=”/build/bundle.js”
charset=”utf-8">
</script>

Problem solved (or at least worked around).

--

--