【问题标题】:Cannot find node module fs when bundling module via scalajs-bundler通过scalajs-bundler捆绑模块时找不到节点模块fs
【发布时间】:2017-06-21 16:43:23
【问题描述】:

我正在尝试将 scala.js 应用程序连接到节点模块。我以前没有这样做过。

fastOptJS::webpack 上,我遇到了构建失败:

target/scala-2.12/scalajs-bundler/main/node_modules/fs doesn't exist
target/scala-2.12/scalajs-bundler/main/node_modules/fs.webpack.js doesn't exist
target/scala-2.12/scalajs-bundler/main/node_modules/fs.web.js doesn't exist
target/scala-2.12/scalajs-bundler/main/node_modules/fs.js doesn't exist
target/scala-2.12/scalajs-bundler/main/node_modules/fs.json doesn't exist

build.sbt

enablePlugins(ScalaJSPlugin, ScalaJSBundlerPlugin)

name := "Toon Brew"

scalaVersion := "2.12.2"

scalaJSUseMainModuleInitializer := true

libraryDependencies += "be.doeraene" %%% "scalajs-jquery" % "0.9.1"

skip in packageJSDependencies := false

jsDependencies += "org.webjars" % "jquery" % "2.1.4" / "2.1.4/jquery.js"

npmDependencies in Compile += "fantasy-names" -> "1.1.2"

plugins.sbt

addSbtPlugin("org.scala-js" % "sbt-scalajs" % "0.6.17")

addSbtPlugin("ch.epfl.scala" % "sbt-scalajs-bundler" % "0.6.0")

立面

package toonbrew

import scala.scalajs.js
import scala.scalajs.js.annotation.JSImport

@JSImport("fantasy-names", JSImport.Namespace)
@js.native
object FantasyNames extends js.Object {
  def names(cat: String, subCat: String, names: Int, gender: Int): js.Array[String] = js.native
}

entire repo

如何解决此错误?

【问题讨论】:

标签: scala.js scalajs-bundler


【解决方案1】:

通过扩展 scalajs-bundler 默认 webpack 配置来忽略 fs

no-fs.webpack.config.js

module.exports = require('./scalajs.webpack.config');

module.exports.node = {fs: 'empty'};

build.sbt

webpackConfigFile := Some(baseDirectory.value / "no-fs.webpack.config.js")

感谢@julien-richard-foy

【讨论】:

    猜你喜欢
    • 2017-01-08
    • 2022-01-03
    • 2021-11-16
    • 2022-12-15
    • 2018-07-10
    • 1970-01-01
    • 2016-10-13
    相关资源
    最近更新 更多