scalacenter / scalajs-bundler

https://scalacenter.github.io/scalajs-bundler
Other
235 stars 101 forks source link

Error parsing webpack stats output #423

Open ptrdom opened 2 years ago

ptrdom commented 2 years ago

fullOptJS::webpack threw the following error for https://github.com/ptrdom/akka-http-slinky-endpoints4s:

[error] Error parsing webpack stats output
[error] /warnings(0)/moduleName: JsonValidationError(List(error.path.missing),WrappedArray())
[error] /warnings(1)/moduleName: JsonValidationError(List(error.path.missing),WrappedArray())
[error] /warnings(2)/moduleName: JsonValidationError(List(error.path.missing),WrappedArray())

JSON output was:

"warnings":[{"message":"asset size limit: The following asset(s) exceed the recommended size limit (244 KiB).\nThis can impact web perform
ance.\nAssets: \n  clientprod-opt.109ea631b1f71d35c84e.bundle.js (622 KiB)","stack":"AssetsOverSizeLimitWarning: asset size limit: The following asset(s) exceed the recommended size limit (244 KiB).\nThis can impact web performance.\nAssets: \n  clientprod-opt.109ea
631b1f71d35c84e.bundle.js (622 KiB)\n    at C:\\Users\\Domantas\\IdeaProjects\\open-source\\akka-http-slinky-endpoints4s\\client\\prod\\target\\scala-2.13\\scalajs-bundler\\main\\node_modules\\webpack\\lib\\performance\\SizeLimitsPlugin.js:134:7\n    at Hook.eval [a
s callAsync] (eval at create (C:\\Users\\Domantas\\IdeaProjects\\open-source\\akka-http-slinky-endpoints4s\\client\\prod\\target\\scala-2.13\\scalajs-bundler\\main\\node_modules\\tapable\\lib\\HookCodeFactory.js:33:10), <anonymous>:9:1)\n    at Hook.CALL_ASYNC_DELEG
ATE [as _callAsync] (C:\\Users\\Domantas\\IdeaProjects\\open-source\\akka-http-slinky-endpoints4s\\client\\prod\\target\\scala-2.13\\scalajs-bundler\\main\\node_modules\\tapable\\lib\\Hook.js:18:14)\n    at C:\\Users\\Domantas\\IdeaProjects\\open-source\\akka-http-s
linky-endpoints4s\\client\\prod\\target\\scala-2.13\\scalajs-bundler\\main\\node_modules\\webpack\\lib\\Compiler.js:804:27\n    at C:\\Users\\Domantas\\IdeaProjects\\open-source\\akka-http-slinky-endpoints4s\\client\\prod\\target\\scala-2.13\\scalajs-bundler\\main\\
node_modules\\neo-async\\async.js:2818:7\n    at done (C:\\Users\\Domantas\\IdeaProjects\\open-source\\akka-http-slinky-endpoints4s\\client\\prod\\target\\scala-2.13\\scalajs-bundler\\main\\node_modules\\neo-async\\async.js:3522:9)\n    at alreadyWritten (C:\\Users\
\Domantas\\IdeaProjects\\open-source\\akka-http-slinky-endpoints4s\\client\\prod\\target\\scala-2.13\\scalajs-bundler\\main\\node_modules\\webpack\\lib\\Compiler.js:647:8)\n    at C:\\Users\\Domantas\\IdeaProjects\\open-source\\akka-http-slinky-endpoints4s\\client\\
prod\\target\\scala-2.13\\scalajs-bundler\\main\\node_modules\\webpack\\lib\\Compiler.js:735:19\n    at C:\\Users\\Domantas\\IdeaProjects\\open-source\\akka-http-slinky-endpoints4s\\client\\prod\\target\\scala-2.13\\scalajs-bundler\\main\\node_modules\\graceful-fs\\
graceful-fs.js:123:16\n    at FSReqCallback.readFileAfterClose [as oncomplete] (node:internal/fs/read_file_context:68:3)"},{"message":"entrypoint size limit: The following entrypoint(s) combined asset size exceeds the recommended limit (244 KiB). This can impact web
 performance.\nEntrypoints:\n  clientprod-opt (622 KiB)\n      clientprod-opt.109ea631b1f71d35c84e.bundle.js\n","stack":"EntrypointsOverSizeLimitWarning: entrypoint size limit: The following entrypoint(s) combined asset size exceeds the recommended limit (244 KiB). 
This can impact web performance.\nEntrypoints:\n  clientprod-opt (622 KiB)\n      clientprod-opt.109ea631b1f71d35c84e.bundle.js\n\n    at C:\\Users\\Domantas\\IdeaProjects\\open-source\\akka-http-slinky-endpoints4s\\client\\prod\\target\\scala-2.13\\scalajs-bundler\
\main\\node_modules\\webpack\\lib\\performance\\SizeLimitsPlugin.js:139:7\n    at Hook.eval [as callAsync] (eval at create (C:\\Users\\Domantas\\IdeaProjects\\open-source\\akka-http-slinky-endpoints4s\\client\\prod\\target\\scala-2.13\\scalajs-bundler\\main\\node_mo
dules\\tapable\\lib\\HookCodeFactory.js:33:10), <anonymous>:9:1)\n    at Hook.CALL_ASYNC_DELEGATE [as _callAsync] (C:\\Users\\Domantas\\IdeaProjects\\open-source\\akka-http-slinky-endpoints4s\\client\\prod\\target\\scala-2.13\\scalajs-bundler\\main\\node_modules\\ta
pable\\lib\\Hook.js:18:14)\n    at C:\\Users\\Domantas\\IdeaProjects\\open-source\\akka-http-slinky-endpoints4s\\client\\prod\\target\\scala-2.13\\scalajs-bundler\\main\\node_modules\\webpack\\lib\\Compiler.js:804:27\n    at C:\\Users\\Domantas\\IdeaProjects\\open-s
ource\\akka-http-slinky-endpoints4s\\client\\prod\\target\\scala-2.13\\scalajs-bundler\\main\\node_modules\\neo-async\\async.js:2818:7\n    at done (C:\\Users\\Domantas\\IdeaProjects\\open-source\\akka-http-slinky-endpoints4s\\client\\prod\\target\\scala-2.13\\scala
js-bundler\\main\\node_modules\\neo-async\\async.js:3522:9)\n    at alreadyWritten (C:\\Users\\Domantas\\IdeaProjects\\open-source\\akka-http-slinky-endpoints4s\\client\\prod\\target\\scala-2.13\\scalajs-bundler\\main\\node_modules\\webpack\\lib\\Compiler.js:647:8)\
n    at C:\\Users\\Domantas\\IdeaProjects\\open-source\\akka-http-slinky-endpoints4s\\client\\prod\\target\\scala-2.13\\scalajs-bundler\\main\\node_modules\\webpack\\lib\\Compiler.js:735:19\n    at C:\\Users\\Domantas\\IdeaProjects\\open-source\\akka-http-slinky-end
points4s\\client\\prod\\target\\scala-2.13\\scalajs-bundler\\main\\node_modules\\graceful-fs\\graceful-fs.js:123:16\n    at FSReqCallback.readFileAfterClose [as oncomplete] (node:internal/fs/read_file_context:68:3)"},{"message":"webpack performance recommendations: 
\nYou can limit the size of your bundles by using import() or require.ensure to lazy load some parts of your application.\nFor more info visit https://webpack.js.org/guides/code-splitting/","stack":"NoAsyncChunksWarning: webpack performance recommendations: \nYou ca
n limit the size of your bundles by using import() or require.ensure to lazy load some parts of your application.\nFor more info visit https://webpack.js.org/guides/code-splitting/\n    at C:\\Users\\Domantas\\IdeaProjects\\open-source\\akka-http-slinky-endpoints4s\
\client\\prod\\target\\scala-2.13\\scalajs-bundler\\main\\node_modules\\webpack\\lib\\performance\\SizeLimitsPlugin.js:153:21\n    at Hook.eval [as callAsync] (eval at create (C:\\Users\\Domantas\\IdeaProjects\\open-source\\akka-http-slinky-endpoints4s\\client\\prod
\\target\\scala-2.13\\scalajs-bundler\\main\\node_modules\\tapable\\lib\\HookCodeFactory.js:33:10), <anonymous>:9:1)\n    at Hook.CALL_ASYNC_DELEGATE [as _callAsync] (C:\\Users\\Domantas\\IdeaProjects\\open-source\\akka-http-slinky-endpoints4s\\client\\prod\\target\
\scala-2.13\\scalajs-bundler\\main\\node_modules\\tapable\\lib\\Hook.js:18:14)\n    at C:\\Users\\Domantas\\IdeaProjects\\open-source\\akka-http-slinky-endpoints4s\\client\\prod\\target\\scala-2.13\\scalajs-bundler\\main\\node_modules\\webpack\\lib\\Compiler.js:804:
27\n    at C:\\Users\\Domantas\\IdeaProjects\\open-source\\akka-http-slinky-endpoints4s\\client\\prod\\target\\scala-2.13\\scalajs-bundler\\main\\node_modules\\neo-async\\async.js:2818:7\n    at done (C:\\Users\\Domantas\\IdeaProjects\\open-source\\akka-http-slinky-
endpoints4s\\client\\prod\\target\\scala-2.13\\scalajs-bundler\\main\\node_modules\\neo-async\\async.js:3522:9)\n    at alreadyWritten (C:\\Users\\Domantas\\IdeaProjects\\open-source\\akka-http-slinky-endpoints4s\\client\\prod\\target\\scala-2.13\\scalajs-bundler\\m
ain\\node_modules\\webpack\\lib\\Compiler.js:647:8)\n    at C:\\Users\\Domantas\\IdeaProjects\\open-source\\akka-http-slinky-endpoints4s\\client\\prod\\target\\scala-2.13\\scalajs-bundler\\main\\node_modules\\webpack\\lib\\Compiler.js:735:19\n    at C:\\Users\\Doman
tas\\IdeaProjects\\open-source\\akka-http-slinky-endpoints4s\\client\\prod\\target\\scala-2.13\\scalajs-bundler\\main\\node_modules\\graceful-fs\\graceful-fs.js:123:16\n    at FSReqCallback.readFileAfterClose [as oncomplete] (node:internal/fs/read_file_context:68:3)
"}]

Seems like moduleName not a mandatory field for warnings in Webpack 5. Relatively simple change. https://github.com/scalacenter/scalajs-bundler/blob/d083e6df3fe2ac795ae16ba69696039bf85f85a3/sbt-scalajs-bundler/src/main/scala/scalajsbundler/Stats.scala#L55

ptrdom commented 2 years ago

There is a really old unmerged PR that solves this - https://github.com/scalacenter/scalajs-bundler/pull/408.

evbo commented 2 years ago

@ptrdom I am similarly getting an error due to loc in WebpackError being optional as well. I think this was caused by the JS library weeknumber (1.2.1) having some funny errors with loc (the line number of the error) missing because I didn't have this happen until I added it as a dependency.

According to the docs, WebPack only mentions message and refers to all other fields as "various" (does that mean they "vary" in existence and should be optional?): https://webpack.js.org/api/stats/#errors-and-warnings

My error is resolved with this addition to your PR:

final case class WebpackError(moduleName: Option[String], message: String, loc: Option[String])
ptrdom commented 2 years ago

@evbo Good eye, I did not spot that in docs. I will implement your suggestion. Maybe adding the stack trace would be a good idea too.

cornerman commented 1 year ago

I am currently hitting this issue when upgrading to the new version with webpack 5. Indeed, there are warnings without a moduleName as already mentioned. Is anything blocking the linked PR?

evbo commented 1 year ago

@cornerman I don't mean to speak for everyone, as I know webpack is still one of the most popular bundlers, but Vite has sort of taken the bundling world by storm! I think many people using Scalajs use Vite, and hence scalajs-bundler might not be getting as much love as it used to.

I know this may be off-topic or counter-productive, but if you can bite the bullet, I migrated to Vite within a day for a fairly large project. And I'm never looking back...

Sjs did an amazing job presenting, so it's a breeze :) https://www.youtube.com/watch?v=dv7fPmgFTNA

I hope this helps...

cornerman commented 1 year ago

@evbo Thanks for sharing your good experience with vite and the video. I want to look into vite, but did not find the time yet.

For now updating to webpack 5 seemed a bit faster. My current workaround is using ignoreWarning in my webpack config.