找不到命令"webpack"



我已经为带有的Rails 6.1项目安装了webpack

yarn add webpack
yarn add -D webpack-cli
yarn add @rails/webpacker@6.0.0-beta.6
bin/rails webpacker:install

直到最近,一切都很顺利,但现在我得到了错误

error Command "webpack" not found.

每当我执行以下任何操作时:

./bin/webpack
./bin/webpack-dev-server
yarn run webpack

我假设它是纱线运行的webpack;在封面下";通过webpack-bin命令,因为我得到了所有3个命令完全相同的输出:

yarn run v1.22.5
error Command "webpack" not found.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

运行

bundle info webpacker 
yarn list --pattern @rails/webpacker

两者都显示我已经安装了测试版6的webpacker

我有包.json

# package.json
{
"name": "ancestors",
"private": true,
"dependencies": {
"@babel/core": "^7.12.10",
"@babel/parser": "^7.13.13",
"@babel/plugin-proposal-class-properties": "^7.13.0",
"@babel/plugin-proposal-object-rest-spread": "^7.13.8",
"@babel/plugin-syntax-dynamic-import": "^7.8.3",
"@babel/plugin-transform-destructuring": "^7.13.0",
"@babel/plugin-transform-regenerator": "^7.12.13",
"@babel/plugin-transform-runtime": "^7.13.10",
"@babel/preset-env": "^7.13.10",
"@rails/actioncable": "^6.0.0",
"@rails/activestorage": "^6.0.0",
"@rails/ujs": "^6.0.0",
"@rails/webpacker": "^6.0.0-beta.6",
"babel-core": "^6.26.3",
"babel-loader": "^8.2.2",
"babel-plugins": "^1.0.0",
"coffee-loader": "^2.0.0",
"coffeescript": "^2.5.1",
"css-loader": "^5.1.3",
"css-minimizer-webpack-plugin": "^1.3.0",
"jquery": "^3.5.1",
"jquery-blockui": "^2.7.0",
"jquery-ui-dist": "^1.12.1",
"mini-css-extract-plugin": "^1.3.9",
"sass": "^1.32.8",
"sass-loader": "^11.0.1",
"style-loader": "^2.0.0",
"turbolinks": "^5.2.0",
"webpack": "^5.11.0"
},
"version": "0.1.0",
"devDependencies": {
"@webpack-cli/serve": "^1.3.0",
"webpack-cli": "^4.2.0",
"webpack-dev-server": "^3.11.2"
},
"engines": {
"yarn": "1.22.5"
},
"scripts": {
"heroku-prebuild": "echo This runs before Heroku installs dependencies.",
"heroku-postbuild": "echo This runs after Heroku installs dependencies, but before Heroku prunes and caches dependencies",
"heroku-cleanup": "echo This runs after Heroku prunes and caches dependencies."
}
}

和webpacker.yml

# webpacker.yml
# Note: You must restart bin/webpack-dev-server for changes to take effect
default: &default
source_path: app/packs
source_entry_path: entrypoints
public_root_path: public
public_output_path: packs
cache_path: tmp/cache/webpacker
webpack_compile_output: true
# Additional paths webpack should lookup modules
# ['app/assets', 'engine/foo/app/assets']
additional_paths: []
# Reload manifest.json on all requests so we reload latest compiled packs
cache_manifest: false
development:
<<: *default
compile: true
# Reference: https://webpack.js.org/configuration/dev-server/
dev_server:
https: false
host: localhost
port: 3035
public: localhost:3035
# Inject browserside javascript that required by both HMR and Live(full) reload
inject_client: true
# Hot Module Replacement updates modules while the application is running without a full reload
hmr: false
# Inline should be set to true if using HMR; it inserts a script to take care of live reloading
inline: true
# Should we show a full-screen overlay in the browser when there are compiler errors or warnings?
overlay: true
# Should we use gzip compression?
compress: true
# Note that apps that do not check the host are vulnerable to DNS rebinding attacks
disable_host_check: true
# This option lets the browser open with your local IP
use_local_ip: false
# When enabled, nothing except the initial startup information will be written to the console.
# This also means that errors or warnings from webpack are not visible.
quiet: false
pretty: 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
# Cache manifest.json for performance
cache_manifest: true

我一辈子都想不出现在缺少了什么安装或配置步骤,尤其是在这个过程中,我不确定是什么破坏了它?

欢迎提出任何建议。

令我非常惊讶的是https://makandracards.com/makandra/432947-how-to-fix-webpack-dev-server-not-found至

运行yarn install--检查文件以修复此错误,

我从以管理员身份执行的命令提示符(在Windows下(使用流浪者重新启动了VirtualBox VM,运行了该命令,我在webpack和webpack dev服务器上遇到的所有问题都得到了解决。

我希望这能帮助到别人。

最新更新