You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

启动sbt时遇scalajs-bundler异常:未定义client/npmDependencies

解决sbt启动时npmDependencies未定义的错误

启动sbt时出现如下异常:

[error] Reference to undefined setting: 
[error] 
[error]   client / npmDependencies from client / npmDependencies (/home/sofoklis/workspace/playjs/build.sbt:26)
[error]      Did you mean client / Compile / npmDependencies ?
[error]  
[error] Use 'last' for the full log.
[warn] Project loading failed: (r)etry, (q)uit, (l)ast, or (i)gnore? (default: r)

问题原因

你使用的sbt-scalajs-bundler版本(0.21.1)中,npmDependencies设置已不再支持全局作用域,必须明确指定作用域(如Compile或Test),错误提示也直接给出了正确的配置方向。

解决方案

修改build.sbt中client项目的配置,将npmDependencies替换为Compile / npmDependencies:

修改前的client配置片段

lazy val client = project
  .enablePlugins(ScalaJSBundlerPlugin)
  .settings(
    scalaJSUseMainModuleInitializer := true,
    libraryDependencies += "org.scala-js" %%% "scalajs-dom" % "1.1.0",
    npmDependencies ++= Seq(
      "jQuery" -> "3.7.0"
    )
  )
  .dependsOn(shared.js)

修改后的client配置片段

lazy val client = project
  .enablePlugins(ScalaJSBundlerPlugin)
  .settings(
    scalaJSUseMainModuleInitializer := true,
    libraryDependencies += "org.scala-js" %%% "scalajs-dom" % "1.1.0",
    Compile / npmDependencies ++= Seq(
      "jQuery" -> "3.7.0"
    )
  )
  .dependsOn(shared.js)

另外,当前使用的sbt-scalajs-bundler 0.21.1与scala-js 1.13.2版本兼容,无需调整插件版本。

内容的提问来源于stack exchange,提问作者Sofoklis

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.14 08:37:01