纱线安装说是最新的,但无法启动 rails 控制台
Yarn install says up to date, yet can't start rails console
我一直在使用 Webpack、Vue.js 和 Rails 开发应用程序。两个月没有问题,但是当我尝试启动 rails 控制台 rails c
、yarn
抱怨包已过期时,不知从何而来:
error An unexpected error occurred: "Unknown language key integrityNodeDoesntMatch".
info If you think this is a bug, please open a bug report with the information provided in "/Users/maksimfedotov/vras/yarn-error.log".
info Visit https://yarnpkg.com/en/docs/cli/check for documentation about this command.
========================================
Your Yarn packages are out of date!
Please run `yarn install` to update.
========================================
然而当我运行yarn install
:
yarn install v1.3.2
[1/4] Resolving packages...
success Already up-to-date.
✨ Done in 0.71s.
我一直在查看 yarn 和 webpacker 文档,尝试了各种 yarn
清理命令,但没有成功。
有趣的是,我仍然可以 运行 服务器,它是唯一抱怨的控制台。
试试这个:NODE_ENV=development yarn install
这是一个老问题,已经解决了,所以我记录下我最后做了什么:
只需删除 node_modules
通常即可解决问题。如果您使用 spring,它也可能会搞砸,因此请考虑 运行 DISABLE_SPRING=1 rails s
看看是否有帮助
尝试通过 运行 宁 spring stop
重新启动 spring。
这为我解决了这个问题,意味着我不需要经常在命令前添加 spring 禁用标志。
上面的命令停止spring: 检查它是否自动重启,运行 spring status
.
解决方案归功于 this comment on GitHub!
只 yarn install
试试,然后 rails c
再试一次
您可以在config/environments/development.rb
中添加
此配置设置
config.webpacker.check_yarn_integrity = false
它还忘记在每个 rails 调用时检查 yarn 完整性,如迁移、启动控制台...,在开发环境中
如果您正在切换更改 yarn.lock
的分支并且只想 运行 一个 rails 控制台而不必每次都保持 运行ning yarn install
开关,您可以将其添加到您的 app/config/development.rb
config.webpacker.check_yarn_integrity = ENV['SKIP_YARN'].nil?
然后当rails抱怨时,你可以简单地这样做
SKIP_YARN=true rails c
就我而言,这解决了问题。
rm -rf yarn.lock
yarn install
由于 node-sass 和节点版本 16 之间的兼容性问题,此问题在 2021 年 4 月再次出现。(I had similar problems here and provide a similar answer to that below here)。
所以我的解决方案是降级节点,直到版本 16 完全兼容。
使用 nvm install 14
安装节点 14,然后使用 nvm alias default 14
.
将其设置为全局默认值
然后:
- 停止 rails 服务器,如果它 运行ning
- 打开一个全新的终端window(这样
node --version
returns14.x
(不是16)
- 运行
spring stop
- 删除
yarn.lock
- 使用
rm -rf node_modules
删除现有节点模块
- 检查
node --version
returns 14。如果没有 运行 nvm install 14
再次。
- 现在使用
yarn install
重新安装模块(如果您没有用于节点 14 的纱线,请使用 npm install --global yarn
安装它)
- 应该会成功!
- 重新启动您的 rails 服务器,它就会工作!
其他有用信息:
- This github issue - this comment 特别是
我一直在使用 Webpack、Vue.js 和 Rails 开发应用程序。两个月没有问题,但是当我尝试启动 rails 控制台 rails c
、yarn
抱怨包已过期时,不知从何而来:
error An unexpected error occurred: "Unknown language key integrityNodeDoesntMatch".
info If you think this is a bug, please open a bug report with the information provided in "/Users/maksimfedotov/vras/yarn-error.log".
info Visit https://yarnpkg.com/en/docs/cli/check for documentation about this command.
========================================
Your Yarn packages are out of date!
Please run `yarn install` to update.
========================================
然而当我运行yarn install
:
yarn install v1.3.2
[1/4] Resolving packages...
success Already up-to-date.
✨ Done in 0.71s.
我一直在查看 yarn 和 webpacker 文档,尝试了各种 yarn
清理命令,但没有成功。
有趣的是,我仍然可以 运行 服务器,它是唯一抱怨的控制台。
试试这个:NODE_ENV=development yarn install
这是一个老问题,已经解决了,所以我记录下我最后做了什么:
只需删除 node_modules
通常即可解决问题。如果您使用 spring,它也可能会搞砸,因此请考虑 运行 DISABLE_SPRING=1 rails s
看看是否有帮助
尝试通过 运行 宁 spring stop
重新启动 spring。
这为我解决了这个问题,意味着我不需要经常在命令前添加 spring 禁用标志。
上面的命令停止spring: 检查它是否自动重启,运行 spring status
.
解决方案归功于 this comment on GitHub!
只 yarn install
试试,然后 rails c
再试一次
您可以在config/environments/development.rb
此配置设置
config.webpacker.check_yarn_integrity = false
它还忘记在每个 rails 调用时检查 yarn 完整性,如迁移、启动控制台...,在开发环境中
如果您正在切换更改 yarn.lock
的分支并且只想 运行 一个 rails 控制台而不必每次都保持 运行ning yarn install
开关,您可以将其添加到您的 app/config/development.rb
config.webpacker.check_yarn_integrity = ENV['SKIP_YARN'].nil?
然后当rails抱怨时,你可以简单地这样做
SKIP_YARN=true rails c
就我而言,这解决了问题。
rm -rf yarn.lock
yarn install
由于 node-sass 和节点版本 16 之间的兼容性问题,此问题在 2021 年 4 月再次出现。(I had similar problems here and provide a similar answer to that below here)。
所以我的解决方案是降级节点,直到版本 16 完全兼容。
使用 nvm install 14
安装节点 14,然后使用 nvm alias default 14
.
然后:
- 停止 rails 服务器,如果它 运行ning
- 打开一个全新的终端window(这样
node --version
returns14.x
(不是16) - 运行
spring stop
- 删除
yarn.lock
- 使用
rm -rf node_modules
删除现有节点模块
- 检查
node --version
returns 14。如果没有 运行nvm install 14
再次。 - 现在使用
yarn install
重新安装模块(如果您没有用于节点 14 的纱线,请使用npm install --global yarn
安装它) - 应该会成功!
- 重新启动您的 rails 服务器,它就会工作!
其他有用信息:
- This github issue - this comment 特别是