我正在从头开始构建React应用。通常,我正在运行npm create-react-app,它会为您生成所有内容。我正在关注本教程https://www.youtube.com/watch?v=deyxI-6C2u4&ab_channel=TraversyMedia,并在说明中包含GitHub存储库。问题是-当我运行“ npm start”时,应该运行此命令
webpack-dev-server --mode development --open --hot
在package.json中写在这里
"scripts": {
"start": "webpack-dev-server --mode development --open --hot",
"build": "./node_modules/.bin/webpack --mode production"
},
如果我手动运行该命令,则该命令有效,但是使用npm start时,会出现以下错误
PS D:\React&Webpack4 boilerplate> npm start
> react-webpack4-boilerplate@1.0.0 start D:\React&Webpack4 boilerplate
> webpack-dev-server --mode development --open --hot
'Webpack4' is not recognized as an internal or external command,
operable program, or batch file.
internal/modules/cjs/loader.js:968
throw err;
^
Error: Cannot find module 'D:\...\webpack-dev-server.js'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:965:15)
at Function.Module._load (internal/modules/cjs/loader.js:841:27)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)
at internal/main/run_main_module.js:17:47 {
code: 'MODULE_NOT_FOUND',
requireStack: []
}
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! react-webpack4-boilerplate@1.0.0 start: `webpack-dev-server --mode development --open --hot`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the react-webpack4-boilerplate@1.0.0 start 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\***\AppData\Roaming\npm-cache\_logs\2020-09-30T18_11_15_755Z-debug.log
答案 0 :(得分:0)
全局安装它,然后尝试将webpack路径添加到局部变量。