New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Non *.js required files provided in resources folder but missing in target/scala-2.11/scalajs-bundler/ #201

Open
christobill opened this Issue Jan 15, 2018 · 2 comments

Comments

Projects
None yet
3 participants
@christobill

christobill commented Jan 15, 2018

Let's say I want to use my-module.js in my project
It requires config.json

 src/main/resources/config.json
 src/main/resources/my-module.js

src/main/resources/my-module.js looks like:

var uuid = require('uuid');
var config = require('./config.json');

console.log(JSON.stringify(config));

module.exports = {
  someUuid: uuid.v4()
};

the corresponding facade:

package example

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

@JSImport("./my-module", JSImport.Namespace)
@js.native
object MyModule extends js.Object {
  val someUuid: String = js.native
}

and the main:

package example

import scala.scalajs.js.JSApp

object Main extends JSApp {

  def main(): Unit = {
    println(MyModule.someUuid)
  }

}

I get the following error:

[info] Running example.Main
[error] module.js:544
[error]     throw err;
[error]     ^
[error] Error: Cannot find module './config.json'
[error]     at Function.Module._resolveFilename (module.js:542:15)
[error]     at Function.Module._load (module.js:472:25)
[error]     at Module.require (module.js:585:17)
[error]     at require (internal/module.js:11:18)
@julienrf

This comment has been minimized.

Member

julienrf commented Jan 15, 2018

We currently delegate to scalaJSNativeLibraries to collect these resources but we might want to make this process more extensible and allow users to define more resources. We could do that by introducing a scalaJSResources key whose default value would be scalaJSNativeLibraries.value.

@sjrd

This comment has been minimized.

Contributor

sjrd commented Jan 15, 2018

Note that scalaJSNativeLibraries will go away in Scala.js 1.x. So instead of defaulting to scalaJSNativeLibraries.value, it would be a good opportunity to make scalaJSResources default to the copy-paste of the implementation of scalaJSNativeLibraries from https://github.com/scala-js/scala-js/blob/e66844601a58f6141df0ad5bb7d5600c0c57c781/sbt-plugin/src/main/scala/org/scalajs/sbtplugin/ScalaJSPluginInternal.scala#L619-L623

@julienrf julienrf added this to the 1.0 milestone Jan 15, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment