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

webpack passing string rather than a map to babel-loader #390

Closed
SunnyTam opened this issue Feb 21, 2017 · 4 comments
Closed

webpack passing string rather than a map to babel-loader #390

SunnyTam opened this issue Feb 21, 2017 · 4 comments
Labels

Comments

@SunnyTam
Copy link

Webpack Version:
2.x

Babel Core Version:
6.x

Babel Loader Version:
6.2.x

Please tell us about your environment:
OSX 10.x

What bug I have found is that I cannot not use devtool: sourcemap. It returns exception below

ERROR in ./src/js/index.js
Module build failed: TypeError: /Users/usr/dir/js/project/src/js/index.js: Cannot create property 'mappings' on string '{"version":3,"sources":["/Users/usr/dir/js/project/src/js/index.js"],"names":["store","render","document","getElementById"],"mappings":";;;;AAAA;;;;AACA;;;;AACA;;AACA;;AACA;;;;AACA;;;;AAEA;;;;;;AAEA;;AAEA,IAAMA,QAAQ,+BAAd;;AAEA,mBAASC,MAAT,CACE;AAAA;AAAA,IAAU,OAAOD,KAAjB;AACE;AAAA;AAAA,MAAQ,oCAAR;AACE,wDAAO,MAAK,GAAZ,EAAgB,yBAAhB;AADF;AADF,CADF,EAOEE,SAASC,cAAT,CAAwB,YAAxB,CAPF,E","sourcesContent":["import React from 'react';\nimport ReactDOM from 'react-dom';\nimport { Provider } from 'react-redux';\nimport { browserHistory, Router, Route } from 'react-router';\nimport injectTapEventPlugin from 'react-tap-event-plugin';\nimport configureStore from './store/configureStore';\n\nimport Main from './components/Main';\n\ninjectTapEventPlugin();\n\nconst store = configureStore();\n\nReactDOM.render(\n  <Provider store={store}>\n    <Router history={browserHistory}>\n      <Route path=\"/\" component={Main} />\n    </Router>\n  </Provider>\n  ,\n  document.getElementById('hotel-chat'),\n);\n"]}'
    at /Users/usr/dir/js/project/node_modules/babel-core/lib/transformation/file/index.js:486:27
    at File.mergeSourceMap (/Users/usr/dir/js/project/node_modules/babel-core/lib/transformation/file/index.js:490:8)
    at File.generate (/Users/usr/dir/js/project/node_modules/babel-core/lib/transformation/file/index.js:729:25)
    at File.transform (/Users/usr/dir/js/project/node_modules/babel-core/lib/transformation/file/index.js:564:17)
    at /Users/usr/dir/js/project/node_modules/babel-core/lib/transformation/pipeline.js:50:19
    at File.wrap (/Users/usr/dir/js/project/node_modules/babel-core/lib/transformation/file/index.js:574:16)
    at Pipeline.transform (/Users/usr/dir/js/project/node_modules/babel-core/lib/transformation/pipeline.js:47:17)
    at transpile (/Users/usr/dir/js/project/node_modules/babel-loader/lib/index.js:46:20)
    at Object.module.exports (/Users/usr/dir/js/project/node_modules/babel-loader/lib/index.js:134:16)
 @ multi (webpack)-dev-server/client?http://localhost:3000 webpack/hot/dev-server ./js/index.js

Finally, I found that webpack calling babel-loader function
module.exports = function (source, inputSourceMap) and passing inputSourceMap as a string rather than map. It makes babel not to response correctly.

So, Do I make any incorrect config so that it pass a string rather than map to babel-loader?
Or should it be fixed on babel-loader?

@Astroxslurg
Copy link

I have exactly the same bug!
Webpack 2.2.1, Babel-core 6.23.1, Babel-loader 6.3.2, Ubuntu 16.04.

One workaround I have found is to rename the file from .js to .jsx.
I have no idea why this is working, but it does the job while waiting for a proper bug fix / correct way to do things.

@danez danez added the bug label Feb 22, 2017
@danez
Copy link
Member

danez commented Feb 22, 2017

I'm not sure what webpack changed, we haven't changed anything related to this.

//cc @sokra @jhnns

@jhnns
Copy link
Contributor

jhnns commented Feb 28, 2017

If inputSourceMap is defined, there must be a loader involved before the babel-loader. The output of the previous loader is just passed to the next loader, so I'd assume a non-standard behavior of this previous loader.

@icatalina
Copy link

Hi! after looking at webpack's documentation, it turns out a JSON parseable string is a valid sourcemap. I raised a PR in to handle this case #889.

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

Successfully merging a pull request may close this issue.

5 participants