如何在Scala.js中使用@JSImport时指定路径?

时间:2017-12-21 12:55:20

标签: scala.js scalajs-bundler

我有:

$ ls -last /home/brandon/workspace/ced2ar/jsgen/target/scala-2.12/scalajs-bundler/main/node_modules/bootstrap/dist/js/bootstrap.min.js
40 -rw-r--r-- 1 brandon brandon 37045 Jul 25  2016 /home/brandon/workspace/ced2ar/jsgen/target/scala-2.12/scalajs-bundler/main/node_modules/bootstrap/dist/js/bootstrap.min.js

@JSImport("node_modules/bootstrap/dist/js/bootstrap.min.js", "jQuery")

然而,当我运行bundler时,我收到以下错误:

[error] ModuleNotFoundError: Module not found: Error: Can't resolve 'node_modules/bootstrap/dist/js/bootstrap.min.js' in '/home/brandon/workspace/ced2ar/jsgen/target/scala-2.12/scalajs-bundler/main'
[error]     at factoryCallback (/home/brandon/workspace/ced2ar/jsgen/target/scala-2.12/scalajs-bundler/main/node_modules/webpack/lib/Compilation.js:269:40)

我还尝试使用bootstrap.min.js的文件名@JSImport。 (注意:我认为一旦我解决了这个问题,我仍然会遇到处理猴子补丁的问题,因为这似乎是引导程序对JQuery所做的。)

1 个答案:

答案 0 :(得分:2)

删除路径中的node_modules部分:

@JSImport("bootstrap/dist/js/bootstrap.min.js", "jQuery")

请确保此文件与CommonJS兼容。