Generated js files have SyntaxError when enabling source map in webpack config
See original GitHub issue- I confirm that this is a issue rather than a question.
Bug report
When enabling source map in the configureWebpack
option, the generated js files have SyntaxErrors. Comment the devtool: "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
- Your OS: Windows 10 1809
- Node.js version: v11.4.0
- Browser version: Google Chrome v72.0.3626.119
- Is this a global or local install? local
- Which package manager did you use for the install? npm
- Does this issue occur when all plugins are disabled? yes
Issue Analytics
- State:
- Created 5 years ago
- Comments:15 (12 by maintainers)
Top Results From Across the Web
source-map-loader - webpack
Extracts source maps from existing source files (from their sourceMappingURL ). ... source map style specified by the devtool option in webpack.config.js.
Read more >webpack not generating source maps - Stack Overflow
I recently had this problem with webpack 3.6.0. No source map files were being generated even though I had devtool: 'source-map' in ...
Read more >The Importance of Source Maps When Debugging - Hatchet
A source map file comprises of a simple JSON object which contains an array of data to help dev tools map any generated...
Read more >ts-node - npm
Any error that is not a TSError is from node.js (e.g. SyntaxError ), and cannot be fixed by TypeScript or ts-node. These are...
Read more >webpack Tutorial: How to Set Up webpack 5 From Scratch
We'll make an src folder to contain all the source files. ... up a Webpack build. Create a webpack.config.js in the root of...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@sinchang You misused lambda.
In
It is pretty valid javascript but may not be what you what to achieve. The correct way is
which returns an object and fails as exprected.
I found that the function
workaroundEmptyStyleChunk
caused this problem. https://github.com/vuejs/vuepress/blob/1850be7f343e54575c64d82c4f0cedc25a9aa91c/packages/%40vuepress/core/lib/build.js#L174-L190The hack was introduced to address this issue. This snippet prepends
styleChunkContent
toappChunkContent
and writes it back to app.[hash].js. When building chunks without sourcemap, each chunk ends with a semicolon (always?). So the prepending operation generates valid code.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
each chunk ends with a semicolon
, leading to invalid code after prepending.