Search code examples
rnode.jsshinysassyarnpkg

Problem with yarn dependency using the rhino R package


I am trying the new R package rhino from the Appsilon team to build shiny apps.

Running on a Windows10 laptop I installed the dependencies node.js and yarn as described in this tutorial.

Here is the output of rhino::diagnostics() :

Windows 10 x64 build 19042
R version 4.1.0 (2021-05-18)
rhino: 1.0.0
node: v16.15.0
yarn: 1.22.15

Running rhino::build_sass() gives me this error:

yarn run v1.22.15
$ sass --no-source-map --style=compressed root/app/styles/main.scss:root/app/static/css/app.min.css
Error reading root\app\styles\main.scss: no such file or directory.
error Command failed with exit code 66.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
Error:
! System command 'yarn' exited with status 66.
i If you can't use Node.js and yarn, try using sass: 'r' configuration.
Run `rlang::last_error()` to see where the error occurred.

I am puzzled by the paths in the call to "sass" that start with "root/app". My app is located in my home directory: "C:/Users/XXX/Documents/workspace/rhino_dummy"

Is it possible that these paths are wrong in the call?


Luckily, the suggested alternative with the deprecated libsass interpreter works for the sass example in the tutorial. It would be nice to have node.js with sass working on Windows10 for future more complex apps.


Edit 1, after Kat's comment

Thanks Kat for the quick feedback. I added sass via yarn add sass and tried again same error:

> rhino::build_sass()
yarn run v1.22.15
warning ..\..\package.json: No license field
$ sass --no-source-map --style=compressed root/app/styles/main.scss:root/app/static/css/app.min.css
Error reading root\app\styles\main.scss: no such file or directory.
error Command failed with exit code 66.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
Error:
! System command 'yarn' exited with status 66.
i If you can't use Node.js and yarn, try using sass: 'r' configuration.
Run `rlang::last_error()` to see where the error occurred.

The warning is coming from the pckage.json file that was created by calling yarn inside my R project folder. It has only minimal content:

# package.json
{
  "dependencies": {
    "sass": "^1.51.0"
  }
}

Out of curiosity, I tried to compile the javascript example, also failed with very similar error regarding folder paths:

> rhino::build_js()
yarn run v1.22.15
warning ..\..\package.json: No license field
$ webpack
assets by status 0 bytes [cached] 1 asset

ERROR in main
Module not found: Error: Can't resolve 'C:\Users\XXX\Documents\workspace\rhino_dummy\.rhino\node\root\app\js\index.js' in 'C:\Users\XXX\Documents\workspace\rhino_dummy\.rhino\node'
resolve 'C:\Users\XXX\Documents\workspace\rhino_dummy\.rhino\node\root\app\js\index.js' in 'C:\Users\XXX\Documents\workspace\rhino_dummy\.rhino\node'
  using description file: C:\Users\XXX\Documents\workspace\rhino_dummy\.rhino\node\package.json (relative path: .)
    Field 'browser' doesn't contain a valid alias configuration using description file: C:\Users\XXX\Documents\workspace\rhino_dummy\.rhino\node\package.json (relative path: ./root/app/js/index.js)
      no extension
        Field 'browser' doesn't contain a valid alias configuration
        C:\Users\XXX\Documents\workspace\rhino_dummy\.rhino\node\root\app\js\index.js doesn't exist
      .js
        Field 'browser' doesn't contain a valid alias configuration
        C:\Users\XXX\Documents\workspace\rhino_dummy\.rhino\node\root\app\js\index.js.js doesn't exist
      .json
        Field 'browser' doesn't contain a valid alias configuration
        C:\Users\XXX\Documents\workspace\rhino_dummy\.rhino\node\root\app\js\index.js.json doesn't exist
      .wasm
        Field 'browser' doesn't contain a valid alias configuration
        C:\Users\XXX\Documents\workspace\rhino_dummy\.rhino\node\root\app\js\index.js.wasm doesn't exist
      as directory
        C:\Users\XXX\Documents\workspace\rhino_dummy\.rhino\node\root\app\js\index.js doesn't exist

webpack 5.69.0 compiled with 1 error in 162 ms
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
Error in `system_yarn()`:
! System command 'yarn' exited with status 1.
Run `rlang::last_error()` to see where the error occurred.

Solution

  • For Node.js functions to work on Windows 10, you'll need to enable Developer Mode on your system as mentioned in our How-to: Use Rhino on Windows article. This is necessary for symbolic links to work on Windows (and the .rhino/node/root file is a symbolic link to the root of the project).

    After you do that, delete the .rhino/node directory from your project, or run rhino:::add_node(clean = TRUE) in the root of your project.