stefanpenner / es6-promise

A polyfill for ES6-style Promises
MIT License
7.29k stars 594 forks source link

Source Map Included in NPM package #235

Closed LandonSchropp closed 8 years ago

LandonSchropp commented 8 years ago

I'm using Webpack to incorporate the es6-promise polyfill as suggested in the readme:

require('es6-promise').polyfill()

The problem is dist/es6-promise.js includes a reference to the source map file. While this is perfectly fine when copying the library into a repository, there's not really an easy way to include the map file in a standard Webpack build. The end result is this error in the browser:

Failed to parse SourceMap: http://localhost:3000/es6-promise.map

Would it be possible to generate a build without the source map comment for incorporating the library with Webpack or to inline the source map?

stefanpenner commented 8 years ago

So webpack is unable to notice there is a source-map file referenced from that file? That seems strange to me..

LandonSchropp commented 8 years ago

I could be missing something with Webpack, but that seems to be the case.

ElForastero commented 8 years ago

Webpack. Nothing unusual, simple config. Trying to use es6-promise in ProvidePlugin. It builds successfully, but after a while node crushes with this:

Error: ENOENT: no such file or directory, open './src/es6-promise.map'

https://cl.ly/2U2u0O1V361P

stefanpenner commented 8 years ago

I'm not quite sure why webpack is unable to locate the source map file.

The browser, and other tools are able to correctly resolve this. I would assume WebPack can as-well.

@ericf do you have any ideas?

stefanpenner commented 8 years ago

Just ran the following:

webpack --devtool source-map dist/es6-promise.js bundle.js
<script src="bundle.js"></script>

and source-maps appear to work correctly when viewed in the browser.

If --devtool source-map is omitted, the output still contains the sourcemap URI, but in an invalid position resulting in the browser ignoring it.


So as a very barebones webpack config seems to "just work", I'm unsure if this is an issue with es6-promise or not. (I suspect not)

stefanpenner commented 8 years ago

@ElForastero im also somewhat perplexed by your issue, as es6-promise does not contain or reference src folder in anyway.

LandonSchropp commented 8 years ago

Okay, I confirmed devtool: 'source-map' in my webpack.config.js file fixes the issue. However, it does seem strange that I have to turn on source maps. Having a source map is great for development, but we don't want to generate one for production.

stefanpenner commented 8 years ago

@LandonSchropp seems unrelated to es6-promise though. Webpack should be dropping source-maps references if they are not used.

It does seem like a default webpack setup accidentally causes this:

If --devtool source-map is omitted, the output still contains the sourcemap URI, but in an invalid position resulting in the browser ignoring it.

connorjclark commented 6 years ago

Found that, at least with Webpack 4, this loader is necessary to prevent the issue: https://github.com/webpack-contrib/source-map-loader

jklegseth commented 5 years ago

Using @Hoten's solution, "devtool": "source-map" does work, as do any of the other valid values for devtool except none. When I use none I get a 404 error for the .map file. Out of 13 packages I have installed, and all their dependent packages, this is the only one that throws the 404 warning, despite many of them have the same folder and file structure.