scala-js / vite-plugin-scalajs

Vite plugin for integration of Scala.js
Apache License 2.0
51 stars 8 forks source link

ENOENT: no such file or directory #6

Closed marmeblade closed 1 year ago

marmeblade commented 1 year ago

At least under windows I got a weird error message:

/main.js (imported by main.js): ENOENT: no such file or directory, open 'C:\Users\xxx\IdeaProjects\xxx\_frontend\      C:\Users\xxx\IdeaProjects\xxx\_frontend\target\scala-3.2.2\frontend-opt\main.js'
error during build:

Notice there is a huge whitespace in front of the path. It turns out, for some reason, this whitespace is generated in the response here:

https://github.com/scala-js/vite-plugin-scalajs/blob/2f94cf3f2eb02d429b08cf99ec7317a91179ab0e/index.ts#L23C2-L34

I was able to fix it by adding a final trim to the output before returning:

  return new Promise((resolve, reject) => {
    child.on('error', err => {
      reject(new Error(`sbt invocation for Scala.js compilation could not start. Is it installed?\n${err}`));
    });
    child.on('close', code => {
      if (code !== 0)
        reject(new Error(`sbt invocation for Scala.js compilation failed with exit code ${code}.`));
      else
        resolve(fullOutput.trimEnd().split('\n').at(-1)!.trim());
    });
  });
}

Should I add a PR for this?

sjrd commented 1 year ago

Thanks for the report. Would you mind posting what's the content of fullOutput when that happens?

marmeblade commented 1 year ago

No problem. Here's the output:

[info] welcome to sbt 1.8.2 (Oracle Corporation Java 20.0.1)
[info] loading global plugins from C:\Users\xxx\.sbt\1.0\plugins
[info] loading settings for project yyy-build from plugins.sbt ...
[info] loading project definition from C:\Users\xxx\IdeaProjects\yyy\project
[info] loading settings for project yyy from build.sbt ...
[info] set current project to yyy (in build file:/C:/Users/xxx/IdeaProjects/yyy/)
[info] compiling 1 Scala source to C:\Users\xxx\IdeaProjects\yyy\_shared\.jvm\target\scala-3.2.2\classes ...   
[info] compiling 1 Scala source to C:\Users\xxx\IdeaProjects\yyy\_shared\.js\target\scala-3.2.2\classes ...    
[info] done compiling
[info] done compiling
[info] Full optimizing C:\Users\xxx\IdeaProjects\yyy\_shared\.js\target\scala-3.2.2\shared-opt
[info] Full optimizing C:\Users\xxx\IdeaProjects\yyy\_shared\.jvm\target\scala-3.2.2\shared-opt
[info] Full optimizing C:\Users\xxx\IdeaProjects\yyy\_frontend\target\scala-3.2.2\frontend-opt
sharedJS / Compile / fullLinkJSOutput
        C:\Users\xxx\IdeaProjects\yyy\_shared\.js\target\scala-3.2.2\shared-opt
sharedJVM / Compile / fullLinkJSOutput
        C:\Users\xxx\IdeaProjects\yyy\_shared\.jvm\target\scala-3.2.2\shared-opt
frontend / Compile / fullLinkJSOutput
        C:\Users\xxx\IdeaProjects\yyy\_frontend\target\scala-3.2.2\frontend-opt

I just replaced the user and project name. Otherwise it's the original. It seams this intendation is done by sbt. For better readability perhaps?

sjrd commented 1 year ago

Ah. You need to set projectID: "frontend" in the configuration, because you have multiple projects in your sbt build. See https://github.com/scala-js/vite-plugin-scalajs#configuration

marmeblade commented 1 year ago

Oh, I understand. I asked myself why he would compile everything instead of just that project. I have to say I fully misinterpreted for what that option was. Thank you very much for your help!