swc-project / swc-loader

Moved to https://github.com/swc-project/pkgs
MIT License
394 stars 29 forks source link

[Possible bug] What does the `parseMap` option does anyway? (Error when that option is used alongside a Webpack Plugin) #72

Closed fcano-ut closed 1 year ago

fcano-ut commented 1 year ago

My build works perfectly, except that when I load this one plugin, bundle-stats-webpack-plugin, it starts failing.

webpack.config.js

new BundleStatsWebpackPlugin({
      compare: true || false, // both give error
      baseline: true || false, // both give error
      html: true,
      json: true,
})

The error I get when compiling (I compiled with the sync: true option to have a prettier error message)

ERROR in ./index.js
Module build failed (from ../node_modules/swc-loader/src/index.js):
SyntaxError: Unexpected token u in JSON at position 0
    at JSON.parse (<anonymous>)
    at Object.<anonymous> (/Users/francisco/Projects/manager-ui/node_modules/swc-loader/src/index.js:83:37)

Disabling the parseMap option fixes this error. The documentation is not very clear on what the parseMap option does, just says to enable it to use swc with babel. I have some babel plugins so I guess I need it?

I want to know if this error might be something of swc, or it's a problem in that particular webpack plugin.

Help is welcome, thanks!

kdy1 commented 1 year ago

It's about sourcemap

fcano-ut commented 1 year ago

Leaving this as a future reference in case anyone faces a similar issue:

This was not related to the webpack plugin, it was related to production builds. Every time I ran that plug-in I was also running the build in production mode.

My guess of what happening is this: since this option is related to source-maps, every time I was running a build with sourcemaps disabled the build would fail.