V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
coool
V2EX  ›  Ruby on Rails

Rails new 命令一直转圈怎么办?

  •  
  •   coool · 2020-11-09 18:47:01 +08:00 · 4613 次点击
    这是一个创建于 1236 天前的主题,其中的信息可能已经有所发展或是发生改变。

    大佬们,执行rails new demo命令时到下面这里一直在转圈,很久也不往下走,求指点:

    warning @rails/webpacker > webpack > watchpack > watchpack-chokidar2 > [email protected]: Chokidar 2 will break on node v14+. Upgrade to chokidar 3 with 15x less dependencies.
    warning @rails/webpacker > webpack > watchpack > watchpack-chokidar2 > chokidar > [email protected]: fsevents 1 will break on node v14+ and could be using insecure binaries. Upgrade to fsevents 2.
    warning @rails/webpacker > webpack > micromatch > snapdragon > source-map-resolve > [email protected]: https://github.com/lydell/resolve-url#deprecated
    warning @rails/webpacker > webpack > micromatch > snapdragon > source-map-resolve > [email protected]: Please see https://github.com/lydell/urix#deprecated
    [2/4] 🚚  Fetching packages...
    [3/4] 🔗  Linking dependencies...
    [4/4] 🔨  Building fresh packages...
    [-/3] ⠂ waiting...
    [-/3] ⠂ waiting...
    [3/3] ⠂ node-sass
    

    就是最后三行,一直在转圈:

    [-/3] ⠂ waiting...
    [-/3] ⠂ waiting...
    [3/3] ⠂ node-sass
    

    已经用下面这两个命令换了代理:

    gem sources --add https://gems.ruby-china.com/ --remove https://rubygems.org/
    
    bundle config mirror.https://rubygems.org https://gems.ruby-china.com
    
    22 条回复    2020-12-24 16:19:55 +08:00
    qiuyi116
        1
    qiuyi116  
       2020-11-09 18:48:47 +08:00 via Android
    我记得是有 node 依赖。npm 也加一次镜像。
    coool
        2
    coool  
    OP
       2020-11-09 18:54:24 +08:00
    @qiuyi116 刚设置了 `npm config set registry https://registry.npm.taobao.org`, 现在还在转圈中……另外上面很多 warning 怎么处理掉?`webpacker`已经更新到 5.2.1 了
    coool
        3
    coool  
    OP
       2020-11-09 19:42:22 +08:00
    弄一天了都没弄好,可能是 rails 门槛太高,高攀不起……
    aristolochic
        4
    aristolochic  
       2020-11-09 22:22:16 +08:00
    node-sass 是有二进制依赖( node-gyp )的,淘宝有预编译的二进制包,但是要想直接使用可不是设置 npm 的镜像源就完事儿了的,具体看 taobao npm 的文档。上面的 warning 忽略就行,都那样。
    fangxing204
        5
    fangxing204  
       2020-11-09 22:41:51 +08:00 via Android
    应该是卡在 yarn install 了,试试设置代理,删掉 node_modules 重试?
    doublechenpaul
        6
    doublechenpaul  
       2020-11-10 09:48:06 +08:00
    @coool 首先不同意你说的门槛太高,第二,可以贴一下 rails 版本及 ruby 版本吗
    coool
        7
    coool  
    OP
       2020-11-10 09:56:45 +08:00
    @fangxing204 刚设置了 `yarn config set sass_binary_site http://cdn.npm.taobao.org/dist/node-sass -g`, `yarn config set registry https://registry.npm.taobao.org` 还是不行,翻墙也不行……

    @aristolochic 执行了

    ```
    echo '\n#alias for cnpm\nalias cnpm="npm --registry=https://registry.npm.taobao.org \
    --cache=$HOME/.npm/.cache/cnpm \
    --disturl=https://npm.taobao.org/dist \
    --userconfig=$HOME/.cnpmrc"' >> ~/.zshrc && source ~/.zshrc
    ```
    也不行。
    coool
        8
    coool  
    OP
       2020-11-10 09:58:52 +08:00
    @doublechenpaul 大佬,ruby 版本:`ruby 2.7.2p137 (2020-10-01 revision 5445e04352) [x86_64-darwin19]`, rails 版本:·Rails 6.0.3.4`。按照这个操作了已经: https://ruby-china.org/wiki/install_ruby_guide
    doublechenpaul
        9
    doublechenpaul  
       2020-11-10 10:08:17 +08:00
    @doublechenpaul 坐标广州,三个圈圈转了 10 分钟左右就安装成功了
    impl
        10
    impl  
       2020-11-10 10:09:03 +08:00 via Android
    Ctrl C 试试?
    coool
        11
    coool  
    OP
       2020-11-10 10:11:44 +08:00
    @doublechenpaul 大佬,啥设置?我这从九点半上班转到现在了。

    @impl Ctrl C => rm -rf demo => rails new demo, 很多次了
    coool
        12
    coool  
    OP
       2020-11-10 10:31:29 +08:00
    哇,删除了所有的代理,本地 global 翻墙,终于成功了……
    msg7086
        13
    msg7086  
       2020-11-10 11:20:43 +08:00
    你如果只是要 new 一个新的 Rails 项目的话,如果用不到 webpack 那可以跳过 webpack 那块。
    coool
        14
    coool  
    OP
       2020-11-10 13:26:58 +08:00
    @msg7086 唉,现在又碰到新问题了,我执行`bin/rails generate controller Say hello goodbye`之后访问`localhost:3000/say/hello`一直报:

    ```
    [Webpacker] Compiling...
    [Webpacker] Compilation failed:
    yarn run v1.22.10
    info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.


    error Command "webpack" not found.
    ```

    执行啥都没用,` bundle exec rails webpacker:install`也不行……

    愁人
    msg7086
        15
    msg7086  
       2020-11-10 14:40:30 +08:00
    我不用 webpack 的,帮不了你……
    doublechenpaul
        16
    doublechenpaul  
       2020-11-10 16:41:08 +08:00
    @coool https://stackoverflow.com/questions/44845143/webpack-command-not-found
    你试试这个,感觉是因为你本地执行路径有问题
    wangkun025
        17
    wangkun025  
       2020-11-11 13:24:23 +08:00
    用 rails5
    wangkun025
        18
    wangkun025  
       2020-11-11 13:30:28 +08:00
    gem install rails -v 5.2.4.4
    rails _5.2.4.4_ new demo
    cd demo
    rails g scaffold Post title:string
    rake db:migrate

    visit http://localhost:3000/posts

    上面的我测试了,没问题。
    lidashuang
        19
    lidashuang  
       2020-11-11 13:38:35 +08:00
    目测 npm 的锅
    iloveayu
        20
    iloveayu  
       2020-11-30 12:29:03 +08:00
    @coool #14
    运行 yarn add @rails/webpacker
    把 webpacker 的依赖都补全了就可以了,
    Rails 6.0.3.4 可以复现你遇到的问题,通过此方式可以解决。
    coool
        21
    coool  
    OP
       2020-11-30 14:35:02 +08:00
    @iloveayu 多谢,这个已经试了很多次了,刚才又试了一次仍然不行。目前用阿里云+vscode remote-ssh 还可以。

    ```
    gyp ERR! command "/usr/local/Cellar/node/15.1.0/bin/node" "/Users/ll/ruby/work/demo/node_modules/node-gyp/bin/node-gyp.js" "rebuild" "--verbose" "--libsass_ext=" "--libsass_cflags=" "--libsass_ldflags=" "--libsass_library="
    gyp ERR! cwd /Users/liuchang/ruby/work/demo/node_modules/node-sass
    gyp ERR! node -v v15.1.0
    gyp ERR! node-gyp -v v3.8.0
    gyp ERR! not ok
    ```

    针对这个报错网上也是一大堆没用的解决方案,开了全局代理也不行。我已经放弃了。
    aristolochic
        22
    aristolochic  
       2020-12-24 16:19:55 +08:00
    @coool (啊居然一个半月之后才看到……我没用 cnpm,据说有巨多坑而且不会影响到 yarn 。我是改在.npmrc 里的,yarn 应该会尊重这个的
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2479 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 50ms · UTC 15:47 · PVG 23:47 · LAX 08:47 · JFK 11:47
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.