Skip to content
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

react & golem example #16

Closed
zac-garland opened this issue Nov 11, 2021 · 3 comments
Closed

react & golem example #16

zac-garland opened this issue Nov 11, 2021 · 3 comments
Assignees
Labels
bug Something isn't working

Comments

@zac-garland
Copy link

Run into errors using the below flow. could be user error or maybe js deps install? any ideas?

I've been able to reproduce twice, but have only tried one computer.

Create the Package


r_proj_folder <- path.expand("~/r_projects")

if (!dir.exists(r_proj_folder)) dir.create(r_proj_folder)

proj_path <- file.path(r_proj_folder,"react.golem")

golem::create_golem(proj_path,open = FALSE)

rstudioapi::openProject(proj_path,newSession = TRUE)

in react.golem package replace app_ui with react example in packer



# scaffold golem
packer::scaffold_golem(react = TRUE, use_cdn = FALSE)

# load the king
library(tidyverse)

# manipulate those files

replace_golem_ui_with_react <- function(msg) {
  # add in react to shiny ui

  replace_index <- read_lines(here::here("R/app_ui.R")) %>%
    tibble(line = .) %>%
    rowid_to_column() %>%
    filter(
      str_detect(line, "app_ui <- function|\\}"),
      !str_detect(line, "\\#")
    ) %>%
    slice(1:2) %>%
    pull(rowid)



  read_lines(here::here("R/app_ui.R")) %>%
    tibble(line = .) %>%
    rowid_to_column() %>%
    filter(!between(rowid, replace_index[[1]], replace_index[[2]])) %>%
    add_row(
      rowid = replace_index[[1]],
      line = 'app_ui <- function(request) {fluidPage(h1("hello, react my old friend"),tagList(reactCDN(),div(id = "app"),tags$script(src = "www/index.js")))}'
    ) %>%
    arrange(rowid) %>%
    pull(line) %>%
    styler::style_text() %>%
    write_lines(here::here("R/app_ui.R"))

  message(glue::glue("it worked {msg}"))
}

replace_golem_ui_with_react("wow!")

bundle error


> packer::bundle()
! Command raised the warning below
running command '"C:\Program Files\nodejs\npm" run production' had status 1
npm WARN lifecycle The node binary used for scripts is C:\Program Files\nodejs\node.exe but npm is using C:\PROGRA~1\nodejs\node.exe itself. Use the `--scripts-prepend-node-path` option to include the path for the node binary npm was executed with.
> react.golem@1.0.0 production react.golem
> webpack --config webpack.prod.js
assets by status 1.57 KiB [cached] 1 asset
./srcjs/index.js 39 bytes [not cacheable] [built] [code generated] [1 error]
ERROR in ./srcjs/index.js
Module build failed (from ./node_modules/@babel/core/lib/index.js):
LoaderRunnerError: Module 'react.golem\node_modules\@babel\core\lib\index.js' is not a loader (must have normal or pitch function)
    at handleResult (react.golem\node_modules\loader-runner\lib\loadLoader.js:49:19)
    at loadLoader (react.golem\node_modules\loader-runner\lib\loadLoader.js:35:10)
    at iteratePitchingLoaders (react.golem\node_modules\loader-runner\lib\LoaderRunner.js:182:2)
    at iteratePitchingLoaders (react.golem\node_modules\loader-runner\lib\LoaderRunner.js:178:10)
    at react.golem\node_modules\loader-runner\lib\LoaderRunner.js:189:18
    at handleResult (react.golem\node_modules\loader-runner\lib\loadLoader.js:53:2)
    at loadLoader (react.golem\node_modules\loader-runner\lib\loadLoader.js:35:10)
    at iteratePitchingLoaders (react.golem\node_modules\loader-runner\lib\LoaderRunner.js:182:2)
    at runLoaders (react.golem\node_modules\loader-runner\lib\LoaderRunner.js:397:2)
    at NormalModule._doBuild (react.golem\node_modules\webpack\lib\NormalModule.js:812:3)
webpack 5.63.0 compiled with 1 error in 699 ms
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! react.golem@1.0.0 production: `webpack --config webpack.prod.js`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the react.golem@1.0.0 production script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\Zacha\AppData\Roaming\npm-cache\_logs\2021-11-11T05_14_47_984Z-debug.log
x Failed to bundle files

sessionInfo:

packer        0.1.1   2021-08-14 [1] CRAN (R 3.6.0)

R 3.6
JohnCoene added a commit that referenced this issue Nov 11, 2021
JohnCoene added a commit that referenced this issue Nov 11, 2021
@JohnCoene
Copy link
Owner

Everything was broken with React, sorry! I pushed a fix but it requires new project, new scaffold.

@JohnCoene JohnCoene self-assigned this Nov 11, 2021
@JohnCoene JohnCoene added the bug Something isn't working label Nov 11, 2021
@zac-garland
Copy link
Author

worked like a charm, thanks @JohnCoene !

image

@JohnCoene
Copy link
Owner

Glad to hear!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants