Rails 6台服务器刚刚停止编译webpack
Rails 6 server just stopped compiling webpack
我发生了一件非常奇怪的事情。
我在我的开发环境中处理这个项目,当我启动 Rails 服务器时,
它会在第一个浏览器请求时编译 webpack。
现在,突然间,这并没有发生,导致所有 javascript 和样式失败,应用程序无法正确呈现。
Rails 服务器控制台甚至不显示 [Webpacker] Compiling… 行
如果我自己启动 webpack-dev-server,它就可以工作。但是由于某种原因 rails 服务器刚刚停止了它自己的工作。我已经在 webpacker.yml 中将行 webpack_compile_output: false 更改为 true 但 rails 服务器仍然没有显示任何与 Webpack 有关的内容。
真是奇怪。我没有添加任何 gem 或更新任何版本的节点或 webpack。我确实在我的机器上将 Git 从 1.9 版全局更新到 2.24 版,仅此而已。
有什么想法吗?
更新:(根据要求,这是我的 config/wenpacker.yml
的内容
default: &default
source_path: app/javascript
source_entry_path: packs
public_root_path: public
public_output_path: packs
cache_path: tmp/cache/webpacker
check_yarn_integrity: false
webpack_compile_output: true
# Additional paths webpack should lookup modules
# ['app/assets', 'engine/foo/app/assets']
resolved_paths: []
# Reload manifest.json on all requests so we reload latest compiled packs
cache_manifest: false
# Extract and emit a css file
extract_css: false
static_assets_extensions:
- .jpg
- .jpeg
- .png
- .gif
- .tiff
- .ico
- .svg
- .eot
- .otf
- .ttf
- .woff
- .woff2
extensions:
- .mjs
- .js
- .sass
- .scss
- .css
- .module.sass
- .module.scss
- .module.css
- .png
- .svg
- .gif
- .jpeg
- .jpg
development:
<<: *default
compile: true
# Verifies that correct packages and versions are installed by inspecting package.json, yarn.lock, and node_modules
check_yarn_integrity: false
# Reference: https://webpack.js.org/configuration/dev-server/
dev_server:
https: false
host: localhost
port: 3035
public: localhost:3035
hmr: false
# Inline should be set to true if using HMR
inline: false
overlay: true
compress: true
disable_host_check: true
use_local_ip: false
quiet: false
headers:
'Access-Control-Allow-Origin': '*'
watch_options:
ignored: '**/node_modules/**'
test:
<<: *default
compile: true
# Compile test packs to a separate directory
public_output_path: packs-test
production:
<<: *default
# Production depends on precompilation of packs prior to booting for performance.
compile: false
# Extract and emit a css file
extract_css: true
# Cache manifest.json for performance
cache_manifest: true
我也遇到了。 通常当运行宁rails s
你会看到这样的东西:
Started GET "/react_test/hello" for ::1 at 2020-05-15 16:54:29 -0700
Processing by ReactTestController#hello as HTML
Rendering react_test/hello.html.erb within layouts/application
[Webpacker] Everything's up-to-date. Nothing to do
如果您对作为 webpack 资源一部分的 js
(或 css
/scss
)进行更改:
Processing by ReactTestController#hello as HTML
Rendering react_test/hello.html.erb within layouts/application
[Webpacker] Compiling...
[Webpacker] Compiled all packs in /Users/foo/public/packs
[Webpacker] Hash: 1ea802b336ed3c771c61
Version: webpack 4.43.0
Time: 4844ms
... truncated for brevity (a list of assets, size, etc)
在某些时候,所有这一切都停止了 - 你会 "have" 到 运行 both rails s
并且 ./bin/webpack-dev-server
手动。到目前为止,我注意到这是在您 运行 webpack-dev-server
时触发的 - 例如更新 config/webpacker.yml
时 - 它确实在该文件本身的注释中说明了这一点:
# Note: You must restart bin/webpack-dev-server for changes to take effect
试试这个解决方法:
- 停止
Rails server
和 webpack-dev-server
- 对您的
/app/javascript/packs/application.js
文件进行一些(临时)更改
- 例如注释掉导入:
//import 'bootstrap'
- 重新启动
rails s
(仅,不 webpack-dev-server
)
- 这会出错 - 因为它缺少注释掉的内容(在本例中
bootstrap
- Undo/uncomment临时改动
- 重新加载页面 - 希望它应该是好的(Webpack 编译等)。
我认为(猜测)caching/sync 问题是 "fixed/(reset?)" 通过对 application.js
进行一些更改
第...
这让我在尝试刺激反射时抓狂。这对我有用(尽管随后 ActionCable connection is not open!
出现了另一个 Stimuils Reflex 问题,此后取得了进展。
- 在终端中执行
rails dev:cache
这可能会禁用缓存
- 运行 你的
rails server
- 此后在终端中重新运行
rails dev:cache
(关闭rails 服务器后)。
在environments/development.rb
中相关的配置是:
config.action_controller.perform_caching = true
config.action_controller.enable_fragment_cache_logging = true
config.cache_store = :memory_store
config.public_file_server.headers = {
'Cache-Control' => "public, max-age=#{2.days.to_i}",
}
所以,我今天 运行 真正进入了这个问题,在阅读了这个问题并做了一些额外的调试之后,我意识到 Rails Webpacker 失败了,因为我已经有另一个项目 运行 Webpacker 混淆了 Rails 版本。
关闭另一个 Webpacker 并重新启动 Rails 服务器立即解决了这个问题。
如果 webpacker 停止响应 application.scss 或 application.js 中的更改,运行 终端中的此命令:
rails webpacker:install
我的情况是我使用 nvm
更改了我的 node
版本。
当一切都停止编译时,我忘记了切换我的版本只是卸载 yarn
这是正常的,因为我正在使用另一个 node
/npm
图像并且因为 yarn
是全局安装的通过 npm
...
所以:
- 运行
bin/rails webpacker:install
,它会说:“Yarn 未安装。请从 https://yarnpkg.com/lang/en/docs/install/ 下载并安装 Yarn
退出!"
- 使用
npm i -g yarn
重新安装 yarn
- 运行你亲爱的
bin/rails s
命令,你就完成了
注意:你会再次看到 [Webpacker] 在你的终端中完成它的工作 ✅
我发生了一件非常奇怪的事情。
我在我的开发环境中处理这个项目,当我启动 Rails 服务器时,
它会在第一个浏览器请求时编译 webpack。
现在,突然间,这并没有发生,导致所有 javascript 和样式失败,应用程序无法正确呈现。
Rails 服务器控制台甚至不显示 [Webpacker] Compiling… 行
如果我自己启动 webpack-dev-server,它就可以工作。但是由于某种原因 rails 服务器刚刚停止了它自己的工作。我已经在 webpacker.yml 中将行 webpack_compile_output: false 更改为 true 但 rails 服务器仍然没有显示任何与 Webpack 有关的内容。
真是奇怪。我没有添加任何 gem 或更新任何版本的节点或 webpack。我确实在我的机器上将 Git 从 1.9 版全局更新到 2.24 版,仅此而已。
有什么想法吗?
更新:(根据要求,这是我的 config/wenpacker.yml
的内容default: &default
source_path: app/javascript
source_entry_path: packs
public_root_path: public
public_output_path: packs
cache_path: tmp/cache/webpacker
check_yarn_integrity: false
webpack_compile_output: true
# Additional paths webpack should lookup modules
# ['app/assets', 'engine/foo/app/assets']
resolved_paths: []
# Reload manifest.json on all requests so we reload latest compiled packs
cache_manifest: false
# Extract and emit a css file
extract_css: false
static_assets_extensions:
- .jpg
- .jpeg
- .png
- .gif
- .tiff
- .ico
- .svg
- .eot
- .otf
- .ttf
- .woff
- .woff2
extensions:
- .mjs
- .js
- .sass
- .scss
- .css
- .module.sass
- .module.scss
- .module.css
- .png
- .svg
- .gif
- .jpeg
- .jpg
development:
<<: *default
compile: true
# Verifies that correct packages and versions are installed by inspecting package.json, yarn.lock, and node_modules
check_yarn_integrity: false
# Reference: https://webpack.js.org/configuration/dev-server/
dev_server:
https: false
host: localhost
port: 3035
public: localhost:3035
hmr: false
# Inline should be set to true if using HMR
inline: false
overlay: true
compress: true
disable_host_check: true
use_local_ip: false
quiet: false
headers:
'Access-Control-Allow-Origin': '*'
watch_options:
ignored: '**/node_modules/**'
test:
<<: *default
compile: true
# Compile test packs to a separate directory
public_output_path: packs-test
production:
<<: *default
# Production depends on precompilation of packs prior to booting for performance.
compile: false
# Extract and emit a css file
extract_css: true
# Cache manifest.json for performance
cache_manifest: true
我也遇到了。 通常当运行宁rails s
你会看到这样的东西:
Started GET "/react_test/hello" for ::1 at 2020-05-15 16:54:29 -0700
Processing by ReactTestController#hello as HTML
Rendering react_test/hello.html.erb within layouts/application
[Webpacker] Everything's up-to-date. Nothing to do
如果您对作为 webpack 资源一部分的 js
(或 css
/scss
)进行更改:
Processing by ReactTestController#hello as HTML
Rendering react_test/hello.html.erb within layouts/application
[Webpacker] Compiling...
[Webpacker] Compiled all packs in /Users/foo/public/packs
[Webpacker] Hash: 1ea802b336ed3c771c61
Version: webpack 4.43.0
Time: 4844ms
... truncated for brevity (a list of assets, size, etc)
在某些时候,所有这一切都停止了 - 你会 "have" 到 运行 both rails s
并且 ./bin/webpack-dev-server
手动。到目前为止,我注意到这是在您 运行 webpack-dev-server
时触发的 - 例如更新 config/webpacker.yml
时 - 它确实在该文件本身的注释中说明了这一点:
# Note: You must restart bin/webpack-dev-server for changes to take effect
试试这个解决方法:
- 停止
Rails server
和webpack-dev-server
- 对您的
/app/javascript/packs/application.js
文件进行一些(临时)更改- 例如注释掉导入:
//import 'bootstrap'
- 例如注释掉导入:
- 重新启动
rails s
(仅,不webpack-dev-server
) - 这会出错 - 因为它缺少注释掉的内容(在本例中
bootstrap
- Undo/uncomment临时改动
- 重新加载页面 - 希望它应该是好的(Webpack 编译等)。
我认为(猜测)caching/sync 问题是 "fixed/(reset?)" 通过对 application.js
第...
这让我在尝试刺激反射时抓狂。这对我有用(尽管随后 ActionCable connection is not open!
出现了另一个 Stimuils Reflex 问题,此后取得了进展。
- 在终端中执行
rails dev:cache
这可能会禁用缓存 - 运行 你的
rails server
- 此后在终端中重新运行
rails dev:cache
(关闭rails 服务器后)。
在environments/development.rb
中相关的配置是:
config.action_controller.perform_caching = true
config.action_controller.enable_fragment_cache_logging = true
config.cache_store = :memory_store
config.public_file_server.headers = {
'Cache-Control' => "public, max-age=#{2.days.to_i}",
}
所以,我今天 运行 真正进入了这个问题,在阅读了这个问题并做了一些额外的调试之后,我意识到 Rails Webpacker 失败了,因为我已经有另一个项目 运行 Webpacker 混淆了 Rails 版本。
关闭另一个 Webpacker 并重新启动 Rails 服务器立即解决了这个问题。
如果 webpacker 停止响应 application.scss 或 application.js 中的更改,运行 终端中的此命令:
rails webpacker:install
我的情况是我使用 nvm
更改了我的 node
版本。
当一切都停止编译时,我忘记了切换我的版本只是卸载 yarn
这是正常的,因为我正在使用另一个 node
/npm
图像并且因为 yarn
是全局安装的通过 npm
...
所以:
- 运行
bin/rails webpacker:install
,它会说:“Yarn 未安装。请从 https://yarnpkg.com/lang/en/docs/install/ 下载并安装 Yarn 退出!" - 使用
npm i -g yarn
重新安装 yarn
- 运行你亲爱的
bin/rails s
命令,你就完成了
注意:你会再次看到 [Webpacker] 在你的终端中完成它的工作 ✅