question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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:closed
  • Created 5 years ago
  • Comments:15 (12 by maintainers)

github_iconTop GitHub Comments

2reactions
jjyyxxcommented, Feb 28, 2019

@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. The correct way is

() => ({
  devtool: 'source-map'
})

which returns an object and fails as exprected.

1reaction
jjyyxxcommented, Feb 28, 2019

I found that the function workaroundEmptyStyleChunk caused this problem. https://github.com/vuejs/vuepress/blob/1850be7f343e54575c64d82c4f0cedc25a9aa91c/packages/%40vuepress/core/lib/build.js#L174-L190

The hack was introduced to address this issue. This snippet prepends styleChunkContent to appChunkContent 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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found