-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Generated js files have SyntaxError when enabling source map in webpack config #1367
Comments
it's working on my local macOS dev workspace. |
@sinchang Thanks for your test! Could you upload your syntactically correct I have tested under Windows 10 and Ubuntu. Evaluating the
|
@sinchang Thanks for your quick reply. But when I try to evaluate your gist in the browser, the error
persists. Are you sure your gist could run without syntactical problems under macOS? |
@jjyyxx sorry, my fault. build success but open in the browser has the same problem |
@jjyyxx it's working when update config to
|
@sinchang You misused lambda. In () => {
devtool: 'source-map'
// "devtool:" is an unused label
// 'source-map' is an unused string literal expression
} It is pretty valid javascript but may not be what you what to achieve. () => ({
devtool: 'source-map'
}) which returns an object and fails as exprected. |
I found that the function vuepress/packages/@vuepress/core/lib/build.js Lines 174 to 190 in 1850be7
The hack was introduced to address this issue. This snippet prepends BUT, if sourcemap is configured to be generated, webpack will append a comment line to the end of each js chunk, which breaks the precondition of |
A simple workaround is inserting a line break when concatenating @yyx990803 The hack was introduced around a year ago, but its impact to sourcemap might not get considered yet. Could you offer some hints to solve this problem gracefully? |
Maybe we can make a simple judgment before using this workaround: if (!config.devTool) await workaroundEmptyStyleChunk() Since we usually don't need a sourcemap in a real production phase, I think this approach is understandable. |
@jjyyxx I think a more fundamental fix would be having the empty chunk issue fixed in webpack itself... thus getting rid of this hack altogether... |
@shigma I tested the patch and it worked as expected. Is it possible to be added into the next version? I don't think it's a breaking change. And it only introduces an |
@jjyyxx contribution welcome! 😆 |
pr created at #1378 |
Bug report
When enabling source map in the
configureWebpack
option, the generated js files have SyntaxErrors. Comment thedevtool: "source-map"
line solves the problem.Version
1.0.0-alpha.40
Steps to reproduce
git clone https://github.com/jjyyxx/vuepress-1367-repro.git cd vuepress-1367-repro npm run build
What is expected?
Generate valid code.
What is actually happening?
Uncaught SyntaxError: Unexpected token }
happens in app.xxx.js.Other relevant information
The text was updated successfully, but these errors were encountered: